[Tutor] question about looping.

2006-10-06 Thread Doug Potter
Hi, I at trying to create a bunch of text files in a single directory on a Linux system, something like this. import os routers = ['adnc-6321', 'adnp-2341', 'adnw-2632'] for i in routers: os.system('/bin/touch' %s) % i of course this dosn't work. Is there a simple way to get this done?

Re: [Tutor] question about sys.path and importing

2006-10-03 Thread Dick Moores
At 12:30 PM 10/3/2006, you wrote: >Dick Moores wrote: >>At 11:38 AM 10/3/2006, Kent Johnson wrote: >>>Normally you will need to either >>>- make 'mine' be a package, by creating an empty file named >>>site-packages\mine\__init__.py, and changing your imports to include the >>>package name (from min

Re: [Tutor] question about sys.path and importing

2006-10-03 Thread Kent Johnson
Dick Moores wrote: > At 11:38 AM 10/3/2006, Kent Johnson wrote: >> Normally you will need to either >> - make 'mine' be a package, by creating an empty file named >> site-packages\mine\__init__.py, and changing your imports to include the >> package name (from mine import mycalc), or >> - add site-

Re: [Tutor] question about sys.path and importing

2006-10-03 Thread Dick Moores
At 11:38 AM 10/3/2006, Kent Johnson wrote: >Normally you will need to either >- make 'mine' be a package, by creating an empty file named >site-packages\mine\__init__.py, and changing your imports to include the >package name (from mine import mycalc), or >- add site-packages\mine to sys.path, mayb

Re: [Tutor] question about sys.path and importing

2006-10-03 Thread Kent Johnson
Dick Moores wrote: > This morning I was sternly warned by Wingware support not to leave my > module of useful functions in Python25\Lib. So I put it in a > subfolder in site-packages I named "mine". Importing of or from that > module, mycalc.py goes well, to my surprise, because of > > >>> imp

[Tutor] question about sys.path and importing

2006-10-03 Thread Dick Moores
This morning I was sternly warned by Wingware support not to leave my module of useful functions in Python25\Lib. So I put it in a subfolder in site-packages I named "mine". Importing of or from that module, mycalc.py goes well, to my surprise, because of >>> import sys >>> [x for x in sys.pa

Re: [Tutor] Question about startswith() and endswith() in 2.5

2006-09-25 Thread Dick Moores
At 09:04 AM 9/25/2006, Carroll, Barry wrote: >Hello, Dick. > >Let's compare your final startswith method and the endswith method in >is_image_file: > > >>> >s.startswith("er","q","ty") >filename.endswith(('.gif', '.jpg', '.tiff')) > >>> > >Notice that, while startswith has THREE parameters

Re: [Tutor] Question about startswith() and endswith() in 2.5

2006-09-25 Thread Carroll, Barry
> -Original Message- > Date: Mon, 25 Sep 2006 02:59:45 -0700 > From: Dick Moores <[EMAIL PROTECTED]> > Subject: [Tutor] Question about startswith() and endswith() in 2.5 > To: tutor@python.org > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain;

Re: [Tutor] Question about startswith() and endswith() in 2.5

2006-09-25 Thread Dick Moores
Thanks, Kent and Andrei! I sure did miss those doubled parentheses. >>> s = "qwerty" >>> >>> s.startswith(("er","z","ty","qw","98768976","uytruytr")) True >>> s.startswith(("er","z","ty","qe","98768976","uytruytr")) False >>> s.startswith(("er","z","rty","qe","98768976","uytruytr"), 2) True

Re: [Tutor] Question about startswith() and endswith() in 2.5

2006-09-25 Thread Andrei
Dick Moores rcblue.com> writes: > endswith( suffix[, start[, end]]) > Return True if the string ends with the specified suffix, otherwise > return False. suffix can also be a tuple of suffixes to look for. > >>> s.startswith("er","q","ty") > > Traceback (most recent call last): >File "",

Re: [Tutor] Question about startswith() and endswith() in 2.5

2006-09-25 Thread Kent Johnson
Dick Moores wrote: > >>> s.startswith("er","q","ty") > > Traceback (most recent call last): >File "", line 1, in > s.startswith("er","q","ty") > TypeError: slice indices must be integers or None or have an __index__ method > > On http://docs.python.org/whatsnew/other-lang.html I found

[Tutor] Question about startswith() and endswith() in 2.5

2006-09-25 Thread Dick Moores
http://www.python.org/doc/lib/string-methods.html has = startswith( prefix[, start[, end]]) Return True if string starts with the prefix, otherwise return False. prefix can also be a tuple of suffixes to look for. With optional start, test string beginn

Re: [Tutor] question about headers and smtplib

2006-08-01 Thread shawn bright
OK, this worked, please disregard my last. The online docs at python.org told me the answer to that one. Between their example and yours, i am able to make it work. thanks a whole bunch ! shawnOn 7/31/06, Justin Ezequiel <[EMAIL PROTECTED]> wrote: When I first started with Python, I used MimeWrite

Re: [Tutor] question about headers and smtplib

2006-07-31 Thread Justin Ezequiel
When I first started with Python, I used MimeWriter to create E-mails. Then some mail servers rejected my E-mails. Some research (google) indicated (to me) that I needed a MIME-Version header. (Can't recall now if I also needed a Content-Type header.) Anyway, more research (Python docs) indicate

Re: [Tutor] question about headers and smtplib

2006-07-31 Thread Dustin J. Mitchell
shawn bright wrote: > the only difference in one from the other is that in the headers of the > other app (not my python script) > there exist the following lines: > > MIME-Version: 1.0 > X-Mailer: OstroSoft SMTP Control (4.0.20) > Content-Type: text/plain; charset="us-ascii" > Content-Transfer-En

[Tutor] question about headers and smtplib

2006-07-31 Thread shawn bright
Hey there, me again with another question about headers.. if i use my python script to send an email, it gets rejected by some providers. but another app that i use can send the same email and it gets thru. i have sent myself test messages from both apps and looked at the headers. the only differ

Re: [Tutor] question about type str

2006-07-29 Thread shawn bright
gee whiz, i thought i had poured over that line sufficiently.It works now. imagine that.thanks,shawnOn 7/29/06, Python < [EMAIL PROTECTED]> wrote:On Sat, 2006-07-29 at 09:26 -0500, shawn bright wrote: > Hey there,> i have an app with this line.> sys.stderr.write("GET DATA %s %d %d\n" (sound, ti

Re: [Tutor] question about type str

2006-07-29 Thread Python
On Sat, 2006-07-29 at 09:26 -0500, shawn bright wrote: > Hey there, > i have an app with this line. > sys.stderr.write("GET DATA %s %d %d\n" (sound, time_limit, digit_count)) sys.stderr.write("GET DATA %s %d %d\n" % (sound, time_limit, digit_count)) ^

[Tutor] question about type str

2006-07-29 Thread shawn bright
Hey there,i have an app with this line.sys.stderr.write("GET DATA %s %d %d\n" (sound, time_limit, digit_count))it is failing with the following error.Traceback (most recent call last):   File "/usr/share/asterisk/agi-bin/ast_agi_test.agi", line 88, in ?    entered_digits = getNumber(welcome, ti

Re: [Tutor] question about metaclasses

2006-07-12 Thread Kent Johnson
anil maran wrote: > hi pygurus > can you please tell me why we need metaclasses and how to use them Hmm...metaclasses are an advanced topic, first exposure to them usually causes one's brain to explode. Fortunately the condition is only temporary :-) Basically a metaclass is the type of a class

[Tutor] question about metaclasses

2006-07-12 Thread anil maran
hi pyguruscan you please tell me why we need metaclasses and how to use themthanks a lotAnil Do you Yahoo!? Everyone is raving about the all-new Yahoo! Mail Beta.___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] Question regarding commit/backout of a message using the pymqi module

2006-06-22 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi everyone, Could someone help explain what I am doing wrong in this code block? This code block is an excerpt from a larger file that receives transmitted files via IBM WebSphere MQSeries an drops it to the local file system. Transmission of the f

[Tutor] Question on Logging Module

2006-06-20 Thread kieran flanagan
Hi, I have written a number of scripts which write to a remote log. I am using the logging module to produce detailed output. Two questions on this module: 1. One of the scripts loops around for a specified period of time. Previously it would print a message to the console detailing how long it h

Re: [Tutor] Question about network server in python

2006-06-15 Thread Kent Johnson
Tino Dai wrote: > Hi there, > > I am wondering if somebody to could answer a question about > sockets. I have a socket that > is listening, and a client program connects to it. The client program > transfers a name over, and then disconnects from the socket. Now, how > that is done is usi

Re: [Tutor] Question about network server in python

2006-06-15 Thread Kent Johnson
Peter Jessop wrote: > I think the problem here is the 'break' statement. > Does it not put you outside the while loop whereas in order to keep > the server socket open you need it to loop forever. > > I also think that the s.accept should be inside the while loop. There are two loops, I think you

Re: [Tutor] Question about network server in python

2006-06-15 Thread Peter Jessop
import socket host = '' port = 57000 s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) s.bind((host,port)) s.listen(5) while 1: client,addr=s.accept() client.send("Connected to the server\n") #if someCondition: # cliente.clo

Re: [Tutor] Question about network server in python

2006-06-15 Thread Peter Jessop
I think the problem here is the 'break' statement. Does it not put you outside the while loop whereas in order to keep the server socket open you need it to loop forever. I also think that the s.accept should be inside the while loop. ___ Tutor maillist

[Tutor] Question about network server in python

2006-06-15 Thread Tino Dai
Hi there,  I am wondering if somebody to could answer a question about sockets. I have a socket that is listening, and a client program connects to it. The client program transfers a name over, and then disconnects from the socket. Now, how that is done is using a socket.close() call to shut d

Re: [Tutor] Question on regular expressions

2006-05-25 Thread Alan Gauld
> for line in open(r'e:\pycode\out_test.txt','rb') : >output.write( re.sub(r'([^\w\s])', lambda s: chr(int(s.group(), > 16))) % ord(s.group()), line)) > > This generated the traceback: > > File "E:\pycode\sample_decode_file_specials_from_hex.py", line 8 >output.write( re.sub(r'([^\w\s])', l

Re: [Tutor] Question on regular expressions

2006-05-25 Thread Terry Carroll
On Thu, 25 May 2006, Kent Johnson wrote: > Yes, this is a feature of print, it always inserts a newline. Well, you can get rid of the newline by ending with a comma, but it still will insert spaces: >>> for ch in "abc": ... print ch ... a b c >>> for ch in "abc": ... print ch, ... a b c >>>

Re: [Tutor] Question on regular expressions (fwd)

2006-05-25 Thread Terry Carroll
On Thu, 25 May 2006, Alan Gauld wrote: > In general I prefer to use string formatting to convert into hex > format. I'm a big fan of hexlify: >>> from binascii import hexlify >>> s="abc-123" >>> hexlify(s) '6162632d313233' ___ Tutor maillist - Tu

Re: [Tutor] Question on regular expressions

2006-05-25 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Everyone, Thanks for all of your patience on this. I finally got it to work. Here is the completed test code showing what is going on. Not cleaned up yet but it works for proof-of-concept purposes. #!/usr/bin/python import re,base64 # Eva

Re: [Tutor] Question on regular expressions

2006-05-25 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Kent, Sorry for causing so much trouble. I am not married to either a single or multi-line solution one way or another. Just a solution that works. Based on something by Danny Yoo provided, I had started with something like: import re,base6

Re: [Tutor] Question on regular expressions

2006-05-25 Thread Kent Johnson
Andrew Robert wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > When I alter the code to: > > import re,sys > > output = open(r'e:\pycode\new_test.txt','wb') > > for line in open(r'e:\pycode\out_test.txt','rb') : >output.write( re.sub(r'([^\w\s])', lambda s: chr(int(s.group(), 16

Re: [Tutor] Question on regular expressions

2006-05-25 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 lol.. Glutton for punishment I guess. I tried removing the last parentheses but I then get an error that two arguments are passed when three are expected. Danny Yoo wrote: > > >> for line in open(r'e:\pycode\out_test.txt','rb') : >>output.w

Re: [Tutor] Question on regular expressions

2006-05-25 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 When I alter the code to: import re,sys output = open(r'e:\pycode\new_test.txt','wb') for line in open(r'e:\pycode\out_test.txt','rb') : output.write( re.sub(r'([^\w\s])', lambda s: chr(int(s.group(), 16))) , line) output.close() I get the trac

Re: [Tutor] Question on regular expressions

2006-05-25 Thread Danny Yoo
> for line in open(r'e:\pycode\out_test.txt','rb') : >output.write( re.sub(r'([^\w\s])', lambda s: chr(int(s.group(), > 16))) % ord(s.group()), line)) Let's add some whitespace. output.write(re.sub(r'([^\w\s])', lambda s: chr(

Re: [Tutor] Question on regular expressions

2006-05-25 Thread Kent Johnson
Andrew Robert wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Hi all, > > I tried: > > > output = open(r'e:\pycode\new_test.txt','wb') > > for line in open(r'e:\pycode\out_test.txt','rb') : > output.write( re.sub(r'([^\w\s])', lambda s: chr(int(s.group(), > 16))) % ord(s.group

Re: [Tutor] Question on regular expressions

2006-05-25 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi all, I tried: output = open(r'e:\pycode\new_test.txt','wb') for line in open(r'e:\pycode\out_test.txt','rb') : output.write( re.sub(r'([^\w\s])', lambda s: chr(int(s.group(), 16))) % ord(s.group()), line)) This generated the traceback: Fi

Re: [Tutor] Question on regular expressions

2006-05-25 Thread Kent Johnson
Andrew Robert wrote: > Taking this a little further along, I wrote the converted file to a new > file using: > > > import re,sys > > output = open(r'e:\pycode\out_test.txt','wb') > > for line in open(r'e:\pycode\sigh.txt','rb') : > output.write( re.sub(r'([^\w\s])', lambda s: '%%%2X' % > or

Re: [Tutor] Question on regular expressions

2006-05-25 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Great! Taking this a little further along, I wrote the converted file to a new file using: import re,sys output = open(r'e:\pycode\out_test.txt','wb') for line in open(r'e:\pycode\sigh.txt','rb') : output.write( re.sub(r'([^\w\s])', lambda s:

Re: [Tutor] Question on regular expressions

2006-05-25 Thread Kent Johnson
Andrew Robert wrote: > The python method inserts extra blank lines after each hex value line. > Does anyone know why this might be? > > Is the print statement inserting a artificial new line character? Yes, this is a feature of print, it always inserts a newline. To avoid this, use sys.stdout.wr

Re: [Tutor] Question on regular expressions

2006-05-25 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Everyone I did a comparison of the output between the perl and python methodology. They do basically the same thing but the perl form seems to be more "true" The python method inserts extra blank lines after each hex value line. For example: O

Re: [Tutor] Question on regular expressions (fwd)

2006-05-24 Thread Alan Gauld
> Your code put me right on track. > > - From that point, I crafted the following code. > > What is confusing is how to take the captured character and > transform it > into a 3 digit hex value. In general I prefer to use string formatting to convert into hex format. print "%3X% % myValue you

Re: [Tutor] Question on regular expressions

2006-05-24 Thread Alan Gauld
> a = open(r'e:\pycode\csums.txt','rb').readlines() > > for line in a: >print re.sub(r'([^\w\s])', lambda s: '%%%2X' % ord(s.group()), > line) Or just for line in open(r'e:\pycode\csums.txt','rb'): print. > Breaking down the command, you appear to be calling an un-named > function >

Re: [Tutor] Question on regular expressions

2006-05-24 Thread Kent Johnson
Andrew Robert wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Wow!!.. > > That awesome! > > > My goal was not to make it a one-liner per-se.. > > I was simply trying to show the functionality I was trying to duplicate. > > Boiling your one-liner down into a multi-line piece of co

Re: [Tutor] Question on regular expressions (fwd)

2006-05-24 Thread Danny Yoo
[forwarding to tutor, although it looks like Andrew's making some good headway from other messages] -- Forwarded message -- Date: Wed, 24 May 2006 14:59:43 -0400 From: Andrew Robert <[EMAIL PROTECTED]> To: Danny Yoo <[EMAIL PROTECTED]> Subject: Re: [Tutor] Qu

Re: [Tutor] Question on regular expressions

2006-05-24 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Wow!!.. That awesome! My goal was not to make it a one-liner per-se.. I was simply trying to show the functionality I was trying to duplicate. Boiling your one-liner down into a multi-line piece of code, I did: #!c:\python24\python import re,sys

Re: [Tutor] Question on regular expressions

2006-05-24 Thread Karl Pflästerer
On 24 Mai 2006, [EMAIL PROTECTED] wrote: > I have two Perl expressions > > > If windows: > > perl -ple "s/([^\w\s])/sprintf(q#%%%2X#, ord $1)/ge" somefile.txt > > If posix > > perl -ple 's/([^\w\s])/sprintf("%%%2X", ord $1)/ge' somefile.txt > > > > The [^\w\s] is a negated expression stating th

Re: [Tutor] Question on regular expressions

2006-05-24 Thread Danny Yoo
> perl -ple "s/([^\w\s])/sprintf(q#%%%2X#, ord $1)/ge" somefile.txt Hi Andrew, Give me a second. I'm trying to understand the command line switches: (Looking in 'perl --help'...) -p assume loop like -n but print line also, like sed -l[octal] enable line ending proce

[Tutor] Question on regular expressions

2006-05-24 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Everyone, I have two Perl expressions If windows: perl -ple "s/([^\w\s])/sprintf(q#%%%2X#, ord $1)/ge" somefile.txt If posix perl -ple 's/([^\w\s])/sprintf("%%%2X", ord $1)/ge' somefile.txt The [^\w\s] is a negated expression stating th

[Tutor] question about ic.py on Mac OS X

2006-05-21 Thread Ishwinder Kaur Banga
MAC OS version 10.4.6 Python Version 2.4.1 Problem is that the url is valid but the python icglue tells me that it is not found Please help Error Traceback (most recent call last): File "dialect.py", line 166, in ? test("http://diveintopython.org/odbchelper_list.ht

Re: [Tutor] Question on option parser

2006-05-16 Thread Karl Pflästerer
On 16 Mai 2006, [EMAIL PROTECTED] wrote: > Is there a way to leverage optionparser so it can accept input from both > command line and a configuration file? > > Current code block is: > > # > # Parse command line options and automatically build > # help/usage display > # > pars

Re: [Tutor] Question on option parser

2006-05-16 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Kent, If I understood correctly, you meant something like this? # # Parse command line options and automatically build help/usage # display # if len(sys.argv) == 2: infile= open(sys.argv[1],"rb").read()

[Tutor] Question on option parser

2006-05-16 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Everyone, I have a program that I'd would like to enhance flexibility in calling. Is there a way to leverage optionparser so it can accept input from both command line and a configuration file? Current code block is: # # Parse command li

[Tutor] question regarding subprocess.Popen

2006-05-09 Thread Yi Qiang
Hi list, I am launching another python program in my python daemon like this: pobj = subprocess.Popen(tlsmd, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.STDOUT,

Re: [Tutor] question about run time

2006-05-03 Thread Hugo González Monteverde
I have made scripts that work on many files (sometimes just some tens) and appears that filesystem structure caching in Linux is very efficient. That's why it runs very fast later. I've seen this in Slackware, Debian, and RH, so I guess it's just a linux/FS/disk thing. Try doing 'find' combin

Re: [Tutor] question about run time

2006-05-02 Thread Danny Yoo
Hi John, You can try something like the profiler, which will say where most of the program's time is being spent. We can find documentation on the Python profiler here: http://www.python.org/doc/lib/profile.html >From a rough, low-level standpoint, there are tools like 'top' on Linux

Re: [Tutor] question about run time

2006-05-02 Thread Ertl, John
odeAmount) print "Your memory usage is %s KB and your inode usage is %s" % (myUse.memTotal,myUse.inodeTotal) print "Your memory limit is %s KB and your inode limit is %s" % (myUse.memLimit, myUse.inodeLimit) if myUse.memLimit < myUse.memTotal or myUse.inodeLimit < m

Re: [Tutor] question about run time

2006-05-02 Thread Danny Yoo
> I have been using python for sometime...and occasionally I noticed > significant delay before the code would run but unitl now I have been > able to write it off to other things. Now I have a short script that I > wrote to check some files and print out a few lines. > > I have noticed that

Re: [Tutor] question about run time

2006-05-02 Thread Ertl, John
Cc: tutor@python.org Subject:Re: [Tutor] question about run time Ertl, John wrote: > Kent, > > The files are very small (a few hundred lines). Maybe it is a network > issue? But then why is it always slow the first time in the morning? I > don't know network st

Re: [Tutor] question about run time

2006-05-02 Thread Kent Johnson
iginal Message- > From: Kent Johnson [mailto:[EMAIL PROTECTED] > Sent: Tuesday, May 02, 2006 12:06 PM > To: Ertl, John > Cc: tutor@python.org > Subject: Re: [Tutor] question about run time > > Ertl, John wrote: >> I have been using python for sometime.

Re: [Tutor] question about run time

2006-05-02 Thread Ertl, John
EMAIL PROTECTED] Sent: Tuesday, May 02, 2006 12:06 PM To: Ertl, John Cc: tutor@python.org Subject:Re: [Tutor] question about run time Ertl, John wrote: > I have been using python for sometime...and occasionally I noticed > significant delay before the code would run but unitl now

Re: [Tutor] question about run time

2006-05-02 Thread Kent Johnson
Ertl, John wrote: > I have been using python for sometime...and occasionally I noticed > significant delay before the code would run but unitl now I have been able > to write it off to other things. Now I have a short script that I wrote to > check some files and print out a few lines. > > I have

[Tutor] question about run time

2006-05-02 Thread Ertl, John
I have been using python for sometime...and occasionally I noticed significant delay before the code would run but unitl now I have been able to write it off to other things. Now I have a short script that I wrote to check some files and print out a few lines. I have noticed that usually the fir

Re: [Tutor] question concerning deepcopy

2006-04-29 Thread Gregor Lingl
Kent Johnson schrieb: > Gregor Lingl wrote: > >>Thanks, Kent for the hint. It works (of course). >>Skimming through this part of the docs I discovered, that there is a >>special method __deepcopy__. So I also tried using this, adding >> >> def __deepcopy__(self,visit): >> r

Re: [Tutor] question concerning deepcopy

2006-04-29 Thread Kent Johnson
Gregor Lingl wrote: > Thanks, Kent for the hint. It works (of course). > Skimming through this part of the docs I discovered, that there is a > special method __deepcopy__. So I also tried using this, adding > > def __deepcopy__(self,visit): > return self > > to my Vec clas

Re: [Tutor] question concerning deepcopy

2006-04-29 Thread Gregor Lingl
Kent Johnson schrieb: > Gregor Lingl wrote: > >>Hi all of you, ... >>> from copy import deepcopy >> >>> class Vec(tuple): >> def __new__(cls, x, y): >> return tuple.__new__(cls, (x,y)) >> def __abs__(self): >> return (self[0]**2+self[1]**2)**0.5 >> ##

Re: [Tutor] question concerning deepcopy

2006-04-28 Thread Kent Johnson
Gregor Lingl wrote: > Hi all of you, > > I've some Vector class, which is a subclass of tuple and which is > working satisfactorily since long in different contexts. Now I've > constructed objects with attributes of Vec-type, which I wanted to > deepcopy. But that doesn't work, because I can't

[Tutor] question concerning deepcopy

2006-04-28 Thread Gregor Lingl
Hi all of you, I've some Vector class, which is a subclass of tuple and which is working satisfactorily since long in different contexts. Now I've constructed objects with attributes of Vec-type, which I wanted to deepcopy. But that doesn't work, because I can't (deep)copy Vec-s: >>> from cop

Re: [Tutor] Question About Function Arguments and Returned Results

2006-04-11 Thread Kent Johnson
Richard Querin wrote: > > > On 4/11/06, *Kent Johnson* <[EMAIL PROTECTED] > > wrote: > > > There is no need to pass the class object in to the function, you can > create it in the function and return it. A class might be nice because > it gives names to th

Re: [Tutor] Question About Function Arguments and Returned Results

2006-04-11 Thread Richard Querin
On 4/11/06, Kent Johnson <[EMAIL PROTECTED]> wrote: There is no need to pass the class object in to the function, you cancreate it in the function and return it. A class might be nice becauseit gives names to the various values. A dict can also be used for this. Do what feels right :-)To be more sp

[Tutor] Question About Function Arguments and Returned Results

2006-04-11 Thread Richard Querin
I'm a relative newbie writing a function that carries out a bunch of calculations. The function requires about 4 or 5 numeric arguments as input but the data returned from the function call is about a dozen numbers in addition to a list of strings and a fairly long list of numbers (200+).  My quest

Re: [Tutor] Question about list

2006-04-10 Thread Hoffmann
--- Matthew White <[EMAIL PROTECTED]> wrote: > Hi Hoffman, > > It is often useful to use the "for" construct to > process items in a list. > e.g.: > > >>> list1 = [ 'spam!', 2, ['Ted', 'Rock']] > >>> for item in list: > ...print item > spam! > 2 > ['Ted', 'Rock'] > > If you pass a list to

Re: [Tutor] Question about list

2006-04-10 Thread Hoffmann
--- Terry Carroll <[EMAIL PROTECTED]> wrote: > On Mon, 10 Apr 2006, Hoffmann wrote: > > > Hello, > > > > I have a list: list1 = [ 'spam!', 2, ['Ted', > 'Rock'] > > ] > > and I wrote the script below: > > > > i = 0 > > while i < len(list1): > > print list1[i] > > i += 1 > > > > Ok. Thi

Re: [Tutor] Question about list

2006-04-10 Thread Danny Yoo
On Mon, 10 Apr 2006, Hoffmann wrote: > I also would like to print the length of each element > of that list: > > spam! = 1 element > 2 = 1 element > ['Ted', 'Rock'] = 2 elements > > Could anyone, please, give me some hints? The problem is slightly weird, just because you need to clarify what i

Re: [Tutor] Question about list

2006-04-10 Thread Terry Carroll
On Mon, 10 Apr 2006, Hoffmann wrote: > Hello, > > I have a list: list1 = [ 'spam!', 2, ['Ted', 'Rock'] > ] > and I wrote the script below: > > i = 0 > while i < len(list1): > print list1[i] > i += 1 > > Ok. This script will generate as the output each > element of the original list, on

Re: [Tutor] Question about list

2006-04-10 Thread Hoffmann
--- John Fouhy <[EMAIL PROTECTED]> wrote: > Hi Hoffmann, > > On 11/04/06, Hoffmann <[EMAIL PROTECTED]> wrote: > > I have a list: list1 = [ 'spam!', 2, ['Ted', > 'Rock'] ] > > and I wrote the script below: > > > > i = 0 > > while i < len(list1): > > print list1[i] > > i += 1 > > Have you

Re: [Tutor] Question about list

2006-04-10 Thread Matthew White
Hi Hoffman, It is often useful to use the "for" construct to process items in a list. e.g.: >>> list1 = [ 'spam!', 2, ['Ted', 'Rock']] >>> for item in list: ...print item spam! 2 ['Ted', 'Rock'] If you pass a list to the len() function, it will return the number of elenents in the list. e.g

Re: [Tutor] Question about list

2006-04-10 Thread Hoffmann
--- Adam <[EMAIL PROTECTED]> wrote: > On 10/04/06, Hoffmann <[EMAIL PROTECTED]> wrote: > > Hello, > > > > I have a list: list1 = [ 'spam!', 2, ['Ted', > 'Rock'] > > ] > > and I wrote the script below: > > > > i = 0 > > while i < len(list1): > > print list1[i] > > i += 1 > > > > Ok. This s

Re: [Tutor] Question about list

2006-04-10 Thread Adam
On 10/04/06, Hoffmann <[EMAIL PROTECTED]> wrote: > Hello, > > I have a list: list1 = [ 'spam!', 2, ['Ted', 'Rock'] > ] > and I wrote the script below: > > i = 0 > while i < len(list1): > print list1[i] > i += 1 > > Ok. This script will generate as the output each > element of the original

Re: [Tutor] Question about list

2006-04-10 Thread John Fouhy
Hi Hoffmann, On 11/04/06, Hoffmann <[EMAIL PROTECTED]> wrote: > I have a list: list1 = [ 'spam!', 2, ['Ted', 'Rock'] ] > and I wrote the script below: > > i = 0 > while i < len(list1): > print list1[i] > i += 1 Have you read about "for" loops? The pythonic way of looping through a list

[Tutor] Question about list

2006-04-10 Thread Hoffmann
Hello, I have a list: list1 = [ 'spam!', 2, ['Ted', 'Rock'] ] and I wrote the script below: i = 0 while i < len(list1): print list1[i] i += 1 Ok. This script will generate as the output each element of the original list, one per line: spam! 2 ['Ted', 'Rock'] I also would like to print

Re: [Tutor] Question about large numbers of arguments

2006-04-05 Thread Hugo González Monteverde
Dana Robinson wrote: > > Have the functions take large numbers of parameters. > > or > > Create an options class to pass the options around. > > Pythonically, I heard the distinct scream of DICTIONAR in my head. Hugo ___ Tutor maillist - Tut

Re: [Tutor] Question about large numbers of arguments

2006-04-05 Thread Python
On Wed, 2006-04-05 at 12:34 +0100, Alan Gauld wrote: > > Suppose you have a situation where you have a large number of command-line > > options that you will parse with getopt. You want to keep track of these > > as you move around in the code and do various things. > > > > Is it more Pythonic to:

Re: [Tutor] Question about large numbers of arguments

2006-04-05 Thread Alan Gauld
> Suppose you have a situation where you have a large number of command-line > options that you will parse with getopt. You want to keep track of these > as you move around in the code and do various things. > > Is it more Pythonic to: > > Have the functions take large numbers of parameters. > > C

Re: [Tutor] Question about large numbers of arguments

2006-04-04 Thread Bob Gailer
Dana Robinson wrote: > Hello, > > Suppose you have a situation where you have a large number of command-line > options that you will parse with getopt. You want to keep track of these > as you move around in the code and do various things. > > Is it more Pythonic to: > > Have the functions take la

[Tutor] Question about large numbers of arguments

2006-04-04 Thread Dana Robinson
Hello, Suppose you have a situation where you have a large number of command-line options that you will parse with getopt. You want to keep track of these as you move around in the code and do various things. Is it more Pythonic to: Have the functions take large numbers of parameters. or Crea

Re: [Tutor] question...

2006-02-20 Thread Danny Yoo
On Mon, 20 Feb 2006, Samantha Warbey wrote: > I have blocks of text (in notebook files currently) that I need to read > 3 and analyse 3 characters at a time. [This is because I'm studying > genes and codons are three characters in length]. How do I do this using > python? I've currently only bee

[Tutor] question...

2006-02-20 Thread Samantha Warbey
I have blocks of text (in notebook files currently) that I need to read 3 and analyse 3 characters at a time. [This is because I'm studying genes and codons are three characters in length]. How do I do this using python? I've currently only been able to find ways of analysing text line by line,

Re: [Tutor] question about ascii and bytes

2006-02-06 Thread Alan Gauld
> the server wants to get info a certain way. Each message has to start > with an ascii "STX" (literally the three letters, not the standart ascii > 'STX') then it has to have another four bytes that give the length of > the message, then the message itself, then end with an ascii "ENX" > (again,t

[Tutor] question about ascii and bytes

2006-02-06 Thread nephish
ok, so i have sparce documentation from a server that i need to make a socket connection with. the server wants to get info a certain way. Each message has to start with an ascii "STX" (literally the three letters, not the standart ascii 'STX') then it has to have another four bytes that give the

Re: [Tutor] question !

2005-12-20 Thread Brian van den Broek
Krava Magare said unto the world upon 2005-12-19 17:31: > How can I remove and add record ( dictionary type) to a file. This is the > program that I'm working on: the program should create a text file, print > the contents of the text file, read the file after it's been created, add a > reco

Re: [Tutor] question !

2005-12-20 Thread Danny Yoo
On Mon, 19 Dec 2005, Krava Magare wrote: > How can I remove and add record ( dictionary type) to a file. Hi Krava, H... I have to admit that I don't understand the question yet. *grin* It looks like you're already pickling lists into your file. Picking dictionaries should be similar; a

[Tutor] question !

2005-12-19 Thread Krava Magare
 How can I remove and add record ( dictionary type) to a file. This is the program that I'm working on: the program should create a text file, print the contents of the text file, read the file after it's been created, add a record and print the contents of the file, remove a record(s) from the

Re: [Tutor] Question

2005-11-29 Thread Danny Yoo
> > I am a bit new to the *nix environment, as well as brand new to Python > > (perhaps I am biting of a bit much, I know). I was wondering if > > someone could point me in a direction to get started in this > > environment. Hi Erik, I agree; I'd recommend getting used to operating your new Un

Re: [Tutor] Question

2005-11-29 Thread John Fouhy
On 30/11/05, Douglass, Erik <[EMAIL PROTECTED]> wrote: > I am a bit new to the *nix environment, as well as brand new to Python > (perhaps I am biting of a bit much, I know). I was wondering if someone > could point me in a direction to get started in this environment. What apps > to code in, is

[Tutor] Question

2005-11-29 Thread Douglass, Erik
I am a bit new to the *nix environment, as well as brand new to Python (perhaps I am biting of a bit much, I know).  I was wondering if someone could point me in a direction to get started in this environment.  What apps to code in, is there an interactive mode?   Specifically FreeBSD 6.0 r

Re: [Tutor] question about ord

2005-11-15 Thread nephish
lf > Of nephish > Sent: Wednesday, 16 November 2005 9:46 a.m. > To: tutor > Subject: [Tutor] question about ord > > > Hey there, > i am using a script to change a byte into an integer > like this: > a = the byte > value = ord(a) > > but

Re: [Tutor] question about ord

2005-11-15 Thread Python
chr(value) >>> chr(ord('a')) == 'a' True On Tue, 2005-11-15 at 14:46 -0600, nephish wrote: > Hey there, > i am using a script to change a byte into an integer > like this: > a = the byte > value = ord(a) > > but i cant find the operation that can change it back to a byte. > i am

<    4   5   6   7   8   9   10   >