Re: substitution of list elements

2008-07-18 Thread Wolfram Kraus
Am 18.07.2008 14:33, antar2 schrieb: I want to replace each first element in list 5 that is equal to the first element of the list of lists4 by the fourth element. I wrote following code that does not work: list4 = [['1', 'a', 'b', 'c'], ['2', 'd', 't', 'e'], ['8', 'g', 'q', 'f']] list5 = ['1',

Re: Sorted list - how to change it

2006-11-09 Thread Wolfram Kraus
On 09.11.2006 10:52, Lad wrote: > I have a sorted list for example [1,2,3,4,5] and I would like to change > it in a random way > e.g [2,5,3,1,4] or [3,4,1,5,2] or in any other way except being > ordered. > What is the best/easiest > way how to do it? > > Thank you for help > L. > use random.shu

Re: looping question 4 NEWB

2006-07-06 Thread Wolfram Kraus
On 06.07.2006 12:43, manstey wrote: > Hi, > > I often have code like this: > > data='asdfbasdf' > find = (('a','f')('s','g'),('x','y')) > for i in find: >if i[0] in data: >data = data.replace(i[0],i[1]) > > is there a faster way of implementing this? Also, does the if clause > increa

Re: How to measure execution time of a program

2006-06-28 Thread Wolfram Kraus
On 28.06.2006 10:01, Girish Sahani wrote: > Sorry for spamming again, but please also enlighten me with some way to > time a function i.e. to find out how much time each function takes for > execution in a big program. >> Hi all, >> >> Can anyone tell me the simplest way to do it (some code snipp

Re: MySQL

2006-02-16 Thread Wolfram Kraus
rodmc wrote: > I need to write a Python application which connects to a MySQL 5.0 > database. Can anyone point me in the right direction or a compatible > library? > > Best, > > rod > See http://sourceforge.net/projects/mysql-python HTH, Wolfram -- http://mail.python.org/mailman/listinfo/pyt

Re: How to creat a file?

2005-12-02 Thread Wolfram Kraus
sandorf wrote: > I'm new to python. Have a simple question. > > "open" function can only open an existing file and raise a IOerror when > the given file does not exist. How can I creat a new file then? > open the new file in write mode: open('foo', 'w') See: help(open) HTH, Wolfram -- http://ma

Re: How to use a timer in Python?

2005-09-22 Thread Wolfram Kraus
Nico Grubert wrote: > Hi there, > > on a Linux machine running Python 2.3.5. I want to create a file > 'newfile' in a directory '/tmp' only if there is no file 'transfer.lock' > in '/temp'. > A cronjob creates a file 'transfer.lock' in '/temp' directory every 15 > minutes while the cronjob is d

Re: Retrieving and saving images from internet address

2005-07-25 Thread Wolfram Kraus
rock69 wrote: > Hi all :) > > I got this address: > > http://www.infomedia.it/immagini/riviste/covers/cp/cp137.jpg > > and I would like to download that image and save it to a local file. > How do you do that in Python? > Use urllib2: http://docs.python.org/lib/module-urllib2.html http://docs.

Re: Replacing last comma in 'C1, C2, C3' with 'and' so that it reads 'C1, C2 and C3'

2005-07-11 Thread Wolfram Kraus
Ric Da Force wrote: > Hi, > > I have a string such as 'C1, C2, C3'. Without assuming that each bit of > text is of fixed size, what is the easiest way to change this list so that > it reads: > 'C1, C2 and C3' regardless of the length of the string. > > Regards and sorry for the newbie questio

Re: need help with MySQLdb

2005-06-30 Thread Wolfram Kraus
nephish wrote: [...] >> Try the following from the shell (NOT the python shell): >> mysql -u user -p >> [Enter passwd] >> mysql> show databases; >> >> If MyDB isn't in the list either something went wrong with the xampp >> installation or the database for xampp got a different name. (I am no >>

Re: need help with MySQLdb

2005-06-29 Thread Wolfram Kraus
[EMAIL PROTECTED] wrote: > Hey there all, > i have a question about how to point my python install to my sql > database. > > when i enter this: db = MySQLdb.connect(user="user", passwd="pass", > db="myDB") > > i get this: > Traceback (most recent call last): > File "", line 1, in -toplevel- >

Re: catch argc-argv

2005-06-19 Thread Wolfram Kraus
mg wrote: > Hello, > > I am writting bindings for a FEM application. In one of my function > 'initModulename', called when the module is imported, I would like to > get the argc and argv arguments used in the main function of Python. > So, my question is: does the Python API containe fonctions

Re: What's wrong with Zope 3 ?

2005-06-02 Thread Wolfram Kraus
Kay Schluehr wrote: > > Wolfram Kraus wrote: > >> Kay Schluehr wrote: >> >>> The last downloadable release is from november 2004. The Windows >>> installer is configured for Python 2.3(!). The Zope.org main page >>> announces Zope 2.8 beta 2. Is

Re: What's wrong with Zope 3 ?

2005-05-31 Thread Wolfram Kraus
Kay Schluehr wrote: > The last downloadable release is from november 2004. The Windows > installer is configured for Python 2.3(!). The Zope.org main page > announces Zope 2.8 beta 2. Is it stillborn? > > Kay > What you see is not Zope 3, it is Zope X 3. To quote from the X3 information page: "

Re: Incrementing letters

2005-05-27 Thread Wolfram Kraus
Duncan Booth wrote: > Michael wrote: > > >>Hi, >>I've got a string s, and i want to shift all the letters up by one, eg >>a->b, b->c z->a >>In c++ i can do this quite simply with >> >>if(C == 'z') C='a'; >>else C++; >> >>but i can't work out how to do this this in python?? > > impo

Re: Strings for a newbie

2005-05-27 Thread Wolfram Kraus
Malcolm Wooden wrote: > my actual code is: > > for x in range(len(l)): > h = string.split(l[x]) > > where the sentence string is in an array of one element 'l' > Error is: > > Traceback (most recent call last): > File "", line 34, in ? > File "", line 27, in SentenceText > File "C:\P

Re: Incrementing letters

2005-05-27 Thread Wolfram Kraus
Heiko Wundram wrote: > Am Freitag, 27. Mai 2005 13:31 schrieb Michael: > >>if(C == 'z') C='a'; >>else C++; > > > if C == "z": > C = "a" > else: > C = chr(ord(C)+1) > According to the OP's problem (with the assumption that only characters from a-z are given) he might even try a lil LC: >

Re: Strings for a newbie

2005-05-27 Thread Wolfram Kraus
Malcolm Wooden wrote: > I'm trying to get my head around Python but seem to be failing miserably. I > use RealBasic on a Mac and find it an absolute dream! But PythonUGH! > > I want to put a sentence of words into an array, eg "This is a sentence of > words" > > In RB it would be simple: >

Re: doc tags?

2005-05-13 Thread Wolfram Kraus
Wolfram Kriesing wrote: > i was already searching and remember i had seen something like "its not > needed". > > Anyway, are there any doc tags, like in Java/PHPDoc etc, where you can > describe parameters (@param[eter]), return values (@ret[urn]), > attributes (@var), references (@see), etc? >

Re: What's this error then?

2005-05-02 Thread Wolfram Kraus
Sara Khalatbari wrote: > You remember me asking about running a program in my > code...I got a problem here > [...] > & my code is: > #! /usr/bin/env python ^ Remove this space, the line should be: #!/usr/bin/env python > > import os > from os import execl > > os.execl ('/home/sara/PYTHO

Re: Writing to stdout and a log file

2005-04-20 Thread Wolfram Kraus
Mike wrote: I would like my 'print' statements to send its output to the user's screen and a log file. This is my initial attempt: class StdoutLog(file): def __init__(self, stdout, name='/tmp/stdout.log', mode='w',bufsize=-1): super(StdoutLog, self).__init__(name,mode,bufsize) s

Re: display VARCHAR(mysql) and special chars in html

2005-02-23 Thread Wolfram Kraus
Jonas Meurer wrote: hello, my script selects a comment saved as VARCHAR in MySQL and displays it inside an html page. the problem is, that the comment contains several special characters, as mysterious utf-8 hyphens, german umlauts, etc. i could write a function to parse the comment and substitute

Re: python-2.4.msi installation issue

2005-02-03 Thread Wolfram Kraus
[EMAIL PROTECTED] wrote: O/S: Windows XP Home (with Service Pack 2) Downloaded python-2.4.msi from python.org (10,632KB). When I double click on the file from Windows Explorer, the installation process presents the window in which I am prompted to either install for all users (the default) or inst

Re: how to pass attribute name via sys.argv

2005-01-27 Thread Wolfram Kraus
Felix Hebeler wrote: Hi all, I am doing some Python scripting for a while, but I'm not too deep into it yet. So I have a problem I can't solve. I need to call an object attribute: value = object.attrName[0] the problem is, that the attribute name can only be specified at runtime. So what I have is

Associate objects with Tix.Tree

2005-01-15 Thread Wolfram Kraus
Heyho! I want to associate objects with the nodes of a Tix.Tree. Is this possible, because the following example won't work: --8<-- Cut here - import Tix class C: pass root = Tix.Tk() top = Tix.Frame(root, relief=Tix.RAISED, bd=1) tixtree = Tix.Tree(top) tixtree.pack(e

Re: SuSE 9.1: updating to python-2.4

2005-01-10 Thread Wolfram Kraus
Heyho! Torsten Mohr wrote: Hi, along with my distribution SuSE 9.1 came python 2.3.3. I'd like to update to 2.4 now, is this an easy thing to do or will lots of installed modules refuse to work then? I installed Python 2.4 under SuSE 9.1 and had no problems so far. If you install it via "./configur