473,766 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

append to non-existing list

Hello,

if I do this:

for row in sqlsth:
________pkcolum ns.append(row[0].strip())
________etc
without a prior:

pkcolumns = [];
I get this error on first iteration:
UnboundLocalErr or: local variable 'pkcolums' referenced before assignment

I guess that's normal as it's the way python works...?!?

My question is: Is there no way to append to a non existing list?

I am lazy for declaring it first, IMHO it bloats the code, and (don't
know if it's good to say that here) where I come from (php) I was used
to not-needing it...
regards,
Yves
Nov 9 '05
25 7643
Yves Glodt wrote:
Which raises another question... :-)

Is there a possibility to bring together apache and python in a way that
I can embed python into html? What do you mean ?

Or even, write a smallish webserver in python (using twisted maybe)
whose only purpose is to serve pages and execute the embedded code...?

My favorite is TurboGears, a collection of modules and glue that brings
together HTTP server(cherrypy ), template(Kid) and SQL object
store(SQLObject ) that can do serious web developement yet don't need to
read a book before starting.

If you just need the server, cherrypy is pretty good and simple to
start.

Nov 10 '05 #21
Yves Glodt wrote:
Is there a possibility to bring together apache and python in a way that
I can embed python into html?


http://www.onlamp.com/pub/a/python/2...ver_pages.html
http://www.modpython.org/live/mod_py...html#pyapi-psp

</F>

Nov 10 '05 #22
bo****@gmail.co m wrote:
Yves Glodt wrote:
Which raises another question... :-)

Is there a possibility to bring together apache and python in a way that
I can embed python into html?

What do you mean ?


I need this (invalid example-html follows):

<html>
<h1>title of page</h1>

<?py

import time

print "<p>Hello, today is: %s</p>" % (time.ctime())

?>

</html>
Should that not be fairly easy to to, even from scratch, with the
httplib module...?

The advantage would be that I could write a webinterface for my database
and reuse the classes I wrote for the command line app.
Or even, write a smallish webserver in python (using twisted maybe)
whose only purpose is to serve pages and execute the embedded code...?

My favorite is TurboGears, a collection of modules and glue that brings
together HTTP server(cherrypy ), template(Kid) and SQL object
store(SQLObject ) that can do serious web developement yet don't need to
read a book before starting.

If you just need the server, cherrypy is pretty good and simple to
start.


Ok gonna look into that,

regards,
Yves
Nov 10 '05 #23

Yves Glodt wrote:
I need this (invalid example-html follows):

<html>
<h1>title of page</h1>

<?py

import time

print "<p>Hello, today is: %s</p>" % (time.ctime())

?>

</html>

Cheetah template ?

But I like Kid better as I don't want python in HTML, Kid IMO strikes
the balance between python feature and XHTML so the template is still
readable by any XHTML editors.

Nov 10 '05 #24
On Wed, 09 Nov 2005 20:45:52 +0100, bruno at modulix wrote:
If the array does not exist yet, it's created.


Which is what I don't like. It should crash.


Perhaps not *crash* as such. Raise an exception perhaps.

--
Steven.

Nov 10 '05 #25
Yves Glodt <y.*****@sitaso ftware.lu> writes:
Which raises another question... :-)

Is there a possibility to bring together apache and python in a way
that I can embed python into html?
Lots of ways. Most of them aren't really Python, but look a lot like
it.

PSP is most like PHP/ASP/etc., and I believe current mod_python's come
with a PSP processor. Be warned that there's more than one thing
floating around by the name Python Server Pages, and they aren't
completely compatible.

Personally, I prefer Cheetah for this, for three reasons:

1) Cheetah doesn't use X/HTML-like syntax for it's tags, so they don't
interfere with my intelligent X/HTML tools.

2) Cheetah can be used for things other than X/HTML, so you get a
twofer on tools. For my last project, I created the Makefile from a
Cheetah template.

3) Cheetah templates are Classes, so you inherit from them. The same
last project created a top-level template that did the site-wide
banner/nav/etc things, and defined abstracd methods for the
title/content. Pages inherited from that (or in some cases from a
subclass of that) and defined concrete versions of the abstrat
methods. Cheetah templates can inherit from Python classes (which I've
found useful), and Python classes can inherit from Cheetah templates
(which sounds useful, but I haven't used it yet).
Or even, write a smallish webserver in python (using twisted maybe)
whose only purpose is to serve pages and execute the embedded code...?


Well, you could always use the CGIHttpServer module that's in the
standard library for this. Cheetah templates can be tested outside the
sever environment, so you don't need a server to execute the embedded
code.

<mike
--
Mike Meyer <mw*@mired.or g> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Nov 10 '05 #26

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3001
by: swaminathang | last post by:
How will I make a text area append only? for eg. if I have some value already initialized for a text area I can add to it but not edit old value. For eg. in a "problem description" text area data can be appended but none of the old details can be tampered with.
3
23958
by: Jonathan Buckland | last post by:
Can someone give me an example how to append data without having to load the complete XML file. Is this possible? Jonathan
5
4921
by: Barn Yard | last post by:
good morning, im still kind of new to VBA but I have learned some interesting things so far. Right now I am normalizing my survey database so I'm having to run an append query for each question(300 in some surveys). WARNING: I've very new at this so this may not look right. i hope it gives the idea of what I'm trying to accomplish. Before I was just chaning the 1's to 2's then to 3's in the Design view of my query. hope this can save...
2
2712
by: Apple | last post by:
I had create a query with one table and one query, and then create form with that query using wizard, but I can't append or edit data in that form & query. Please help!
3
2350
by: Kevin | last post by:
Hi I have a table that is imported from excel the records are updated as required by the user my question is Can only the new data entered be appended to the table in access ie if i update the table in the morning and import 10 records when i next update the table i want to import only the new data any help would be welcome
0
1418
by: audleman | last post by:
I have an ASP form on my website where a visitor enters information. On submit, the form calls a stored procedure stores in a MS SQL 2000 database. The stored procedure works most of the time, but every once in a while I get an error 3421 (Application uses a value of the wrong type for the current operation) when I try to append the last parameter in the ASP code, which is a Varchar(500). Here's the relevant code: STORED PROCEDURE...
2
12018
by: cb22 | last post by:
I have created a recordset built from scratch, based on data from an external, non-database source. I want to append this recordset to a table in an Access database without using a loop to traverse through each record and add to the table. Any suggestions on what I can use or do to make this possible? Regards.
4
5766
by: pmacdiddie | last post by:
I have an append query that needs to run every time a line item is added to a subform. The append writes to a table that is the source for a pull down box. Problem is that it takes 5 seconds to run. This makes adding lines to an order too slow for the users. The result of the query provides real time availabilty, so I really do need this to work. The tblJobs has only 10,000 records, tblJobsLineItems has 150,000 records.
5
7669
by: jkn | last post by:
Hi all Python 2.4.2 (#1, Apr 26 2006, 23:35:31) on linux2 Type "help", "copyright", "credits" or "license" for more information. Traceback (most recent call last): File "<stdin>", line 1, in ? IOError: invalid mode: a
2
2728
by: kvnil | last post by:
Cheers, I've been struggling all day today with this, maybe you could give me some useful pointers. I would like to (elegantly) concatenate a string out of all node values in a map. I have to do it without using boost (as it is forbidden to use it in our project). (Forgive me for giving a non-compiling code.)
0
9404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10009
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8835
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6651
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.