Re: [Tutor] returning the entire line when regex matches

2009-05-04 Thread Alan Gauld
Mr. Gauld is referring to!! I searched python.org and alan-g.me.uk. Does anyone have a link? I posted a link to the Python howto and my tutorial is at alan-g.me.uk You will find it on the contents frame under Regular Expressions... Its in the Advanced Topics section. -- Alan Gauld Author of

Re: [Tutor] quick question to open(filename, 'r') vs. file(filename, 'r')

2009-05-04 Thread Alan Gauld
"Emile van Sebille" wrote in message news:gtnrtf$pi...@ger.gmane.org... On 5/4/2009 2:50 PM bob gailer said... PDavid wrote: Dear list, in different books I come across different syntax for dealing with files. It seems that open(filename, 'r') and file(filename, 'r') are used interchangeably,

Re: [Tutor] Conversion question

2009-05-04 Thread Alan Gauld
;t think why unless you have a very strange parser at the other end). In that case I think you do need to insert the \x characters. -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python

Re: [Tutor] Conversion question

2009-05-05 Thread Alan Gauld
what the value of that is over struct or int? Can anyone enlighten me about why I'd ever want to use this? -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Replacing fields in lines of various lengths

2009-05-05 Thread Alan Gauld
"Dan Liang" wrote And I put together the code below based on your suggestions, with minor changes and it does work. Good, now your question is? -Begin code #!usr/bin/python tags = { 'noun-prop': 'noun_prop null null'.split(), 'case_def_gen': 'case_d

Re: [Tutor] Tutor Digest, Vol 63, Issue 8

2009-05-05 Thread Alan Gauld
Please use a sensible subject and don;t reporst the whole digest. "Dan Liang" wrote in message Thank you for your help. I have been working on the file, but I still have a problem doing what I wanted. As a reminder, Can you tell us what exactly the problem is? It's easier than us trying to

Re: [Tutor] Replacing fields in lines of various lengths

2009-05-05 Thread Alan Gauld
My turn to apologise for premature sending of email... For some reason I didn't notice the section of mail after the code snippet! Alan G "Dan Liang" wrote in message Now since I have to work on different data format as follows: -Begin data w1\t

Re: [Tutor] Using read() before closing a file

2009-05-05 Thread Alan Gauld
ut if I had closed the file and then did this: res = open('c:/myscripts/simple2.ttt').read(), it would have worked. Thats right because you now open the file for reading, therefore the cursor is repositioned at he start of the file and the mode is set correctly. HTH, -- Alan G

Re: [Tutor] returning the entire line when regex matches

2009-05-05 Thread Alan Gauld
ourse now I am stuck on how to apply the delimiter and search function to the items in the list..? Either call your function on each file as you find it -- no need for a list, or... for f in allfiles: myFunction(f) Provided your function can take the filename as a parameter either met

Re: [Tutor] quick question to open(filename, 'r') vs. file(filename, 'r')

2009-05-05 Thread Alan Gauld
"wesley chun" wrote does anyone have the idiom for the above isinstance() check for 3.x? Test for io.stream (or a derivative) - which is what open now returns. files are no more... Alan G. ___ Tutor maillist - Tutor@python.org http://mail.pyth

Re: [Tutor] quick question to open(filename, 'r') vs. file(filename, 'r')

2009-05-05 Thread Alan Gauld
x27;m not sure citing anything Java does is a good rationale in Python! Hopefully we can do rather better than the horrors of Java :-) -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python

Re: [Tutor] Reset while loop

2009-05-06 Thread Alan Gauld
os *= bufsize f.seek(pos) lines = f.read().split(linesep) f.close() return lines[-2:] def tail_it(fname, bufsize=8192, linesep=os.linesep): while True: new_time = os.stat(tail_fname).st_mtime if new_time > old_time: time.sleep(sec_to_wait)

Re: [Tutor] Reset while loop

2009-05-06 Thread Alan Gauld
"Alan Gauld" wrote f.seek(0, 2) pos, tailsize = divmod(f.tell(), bufsize) if tailsize == 0: pos = max(0, pos-1) pos *= bufsize f.seek(pos) I got confused trying to work out exactly what this was doing. pos is initially the numbe

Re: [Tutor] Reset while loop

2009-05-06 Thread Alan Gauld
led explicitly - it is called implicitly by the file going out of scope at the end of the function - and its good practice to explicitly close the file HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor mail

Re: [Tutor] New beginner book - "Practical Programming"

2009-05-07 Thread Alan Gauld
books. I would be interested in a review if anyone reads it. http://www.pragprog.com/titles/gwpy/practical-programming Based on the excerpt that I read online it looks pretty good. I couldn't see anything to carp about at all. Very impressive. -- Alan Gauld Author of the Learn to P

Re: [Tutor] Need help with registry access

2009-05-07 Thread Alan Gauld
cessing the registry. How you do it over the LAN and how you disable the keyboard I'll leave as an exercise for your investigation! One other option is to look into using WSH via the pythonwin or ctypes API. -- Alan Gauld Author of the Learn to Program web sit

Re: [Tutor] Need help with registry access

2009-05-08 Thread ALAN GAULD
/NonProgrammers http://docs.python.org/tutorial/ Alan Gauld Author of the Learn To Program website http://www.alan-g.me.uk/ - Original Message > From: Christopher Barkley > To: Alan Gauld > Sent: Friday, 8 May, 2009 5:09:25 AM > Subject: Re: [Tutor] Need help with reg

Re: [Tutor] Optparse question: if only certain values are acceptable

2009-05-09 Thread Alan Gauld
values too (via choice) but again catching anything other than X,Y,Z is just as easy using an else clause in your case. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] paramiko again

2009-05-09 Thread Alan Gauld
f stftp.listdir(). Where local_path is wherever you store the files on the local mnachine that you want to transfer. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Parsing Question

2009-05-09 Thread Alan Gauld
ds): print word[1] You should probably be able to do the first for loop as a list comprehension, but I can't think of how to get the split() call embedded into it right now! HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___

Re: [Tutor] Different Command Result Executing in Shell vs. Program

2009-05-09 Thread Alan Gauld
"robert mcquirt" wrote import os os.system('file -b /home/robert/linuxlogotag') This also works fine. The problem is that when I try to replace the hard coded path/name with a string variable for looping, the results are not the same as the shell's. import os, glob path = '/home/robert

Re: [Tutor] paramiko again

2009-05-10 Thread Alan Gauld
may be wrong. But at least you need to pass '/' as your path. sftp.get(os.path.join(dir_path, f), f) dir_path = '/' sftp.get(dir_path, f) If that doesn't work put the join back in... -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/

Re: [Tutor] Sending Email - Outlook 2003 / Overcome SecurityWarning!

2009-05-10 Thread Alan Gauld
dule. This just sends the mail directly to the mail server without going near Outlook. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Triggering code on 1 minute intervale ..

2009-05-10 Thread Alan Gauld
e a python script that runs in the background (a service or daemon) and launces a thread at periodic intrevals. But I'd go with cron/at as the simplest solution. -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___

Re: [Tutor] How to control the not existent keys in a dict

2009-05-10 Thread Alan Gauld
r'] Traceback!!! d.get('Error',False) False HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Guidance needed for script

2009-05-11 Thread Alan Gauld
alking to the User' topic of my tutorial. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] moving files from one dir to another

2009-05-11 Thread Alan Gauld
"Matt Herzog" wrote I sure wish I could for the last line go, shutil.move("src", "dest") That would be cool. So why don't you? What is the problem? -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ __

Re: [Tutor] Alternative for Shelve

2009-05-11 Thread Alan Gauld
x27; : 'Spain'}] populating your dictionary becomes a matter of extracting the data: SELECT DATE, LOCATION FROM DATA WHERE ID = key SQLite has the advantage that the atabase is a single file and it is portable across platforms provided they have Sqlite installed. And its part of the P

Re: [Tutor] Calling method in parent class

2009-05-12 Thread Alan Gauld
option 1 because its explicit and therefore clear what exactly I'm calling. Or should I mix both these approaches? No, do not mix them, that way leads to madness IMHO! :-) -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ _

Re: [Tutor] Calling method in parent class

2009-05-12 Thread Alan Gauld
th a naming convention such as the one above but we still need to do a fair bit of explicit coding. Lisp does it automagically. (You might be able to do something like it in Python using decorators....h.) HTH, -- Alan Gauld Author of the Learn to Program we

Re: [Tutor] Calling method in parent class

2009-05-12 Thread Alan Gauld
ly use the superclass functionality and add a little bit of local processing for any attributes in the child class. -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.

Re: [Tutor] Calling method in parent class

2009-05-12 Thread Alan Gauld
ry overridden method then I'd say that was bad design. -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Calling method in parent class

2009-05-12 Thread Alan Gauld
ase but its not really OO programming, its just programming with objects! The hysteria over abuse of inheritance has kind of thrown the baby out with the bathwater IMHO! -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___

Re: [Tutor] Considering translating bash script to Python to learn

2009-05-12 Thread Alan Gauld
tml parser such as Beautiful Soup that aspect may be worth converting to Python. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Calling method in parent class

2009-05-12 Thread Alan Gauld
this way subclass methods play a role in AUGMENTING THE BEHAVIOUR DEFINED IN THE SUPERCLASS. - end quote -- (caps mine) So at least two well known OOP authorities recognise that such is common practice. -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk

Re: [Tutor] simply moving files

2009-05-12 Thread Alan Gauld
reliable and saves you a lot of extra work checking whether the src and dst are on the same filesystem etc. You should justy be abloe to use shutil.move() What is the probnlem with this (apart from Kent's point that you were not passing filenames originally!) -- Alan Gauld Author of the

Re: [Tutor] simply moving files]]

2009-05-13 Thread Alan Gauld
ar/baz/spam Another way of doing the same thing would be with join: '/'.join([src,fnames]) or for platform independance: os.sep.join([src,fnames]) HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ __

Re: [Tutor] Calling method in parent class

2009-05-13 Thread Alan Gauld
ur but is very common in practice. -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Retrieving Data from Pmw.EntryFeild

2009-05-13 Thread Alan Gauld
1st field and 3rd field? And what do you mean by *both* rows? You have 3 rows? It is not clear what exactly you are asking for. It is also not clear what you don't understand. Can you give us an example of what you have done and explain how it fails? -- Alan Gauld Author of the Learn to P

Re: [Tutor] (a, b) = (l[0:2], l[2:])

2009-05-13 Thread Alan Gauld
"Jabin Jezreel" wrote What is the idiomatic way to write the right side of (a, b) = (l[0:2], l[2:]) ? (not worried about the parens, just the splitting of the sequence) I think you have it. I'm not aware of any better way. -- Alan Gauld Author of the Learn to Progra

Re: [Tutor] saveing and loading text data

2009-05-13 Thread Alan Gauld
"Jacob Mansfield" wrote hi everyone, I'm a bit new here but i was wondering if someone could check some of my code, it's not doing quite what it's meant to. That's not very specific. What is it meant to do? What does it actually do? Do you get any error messages? If so post them in the emai

Re: [Tutor] Sorting a list

2009-05-13 Thread Alan Gauld
rd',1,2,3] sorted(L, cmp=comp) ['word', 'picture', 1, 2, 3, 3, 4] HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] t = (1, *(2, 3))

2009-05-14 Thread Alan Gauld
t;ts" case above? That I don't know. The asterisk notation can only be used for unpacking function arguments, but why it is limited to that role I don't know...? -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ __

Re: [Tutor] cheetah is extremely hard to debug -error messages are non indicative TypeError: cannotconcatenate 'str' and 'int' objects

2009-05-14 Thread Alan Gauld
p you need to send the complete message for each error. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Python popen command using cat > textfile .... how toterminate

2009-05-14 Thread Alan Gauld
bprocess. It is slightly more complex than popen or commands but it is future proof (for now at least!) Simple example: import subprocess lsout = subprocess.Popen('ls -ls', shell=True, stdout=subprocess.PIPE).stdout print lsout.read() -- Alan Gauld Author of the Learn to Progr

Re: [Tutor] Python popen command using cat > textfile .... how toterminate

2009-05-15 Thread Alan Gauld
x or Python. In *nix use touch and in Python use open(foo,'w').close() When working in Python, every time you are tempted to call a unix command via os.system/popen etc check to see if there is a way to do it from within python fiorst. There often is. HTH, -- Alan Gauld Author

Re: [Tutor] Shared FIFO?

2009-05-18 Thread Alan Gauld
issues). But a lot will depend on transaction volumes etc. If you never, or rarely, have concurrent accesses then using a text file might work. Or you could do it all in memory via a long running process and a queue. But if volumes are (or could become) high or bursty I'd go for the SQL rou

Re: [Tutor] performance loss -- profiling

2009-05-18 Thread Alan Gauld
d? Did you index the key columns? - Directory path traversal - have you moved the location of any key files? Either the executables/scriopts or the data? Just some ideas before you resort to profiling. HTH, -- Alan Gauld Author of the Learn to Program web site htt

Re: [Tutor] Replacement for __del__

2009-05-18 Thread Alan Gauld
"Strax-Haber, Matthew (LARC-D320)" wrote My class sub-types dict. In __init__, there is a call to self.update(pickle.load()). For some reason, this triggers __del__. Why? A pure guess, but maybe the pickle load creates a new instance which replaces the original which then gets garbage col

Re: [Tutor] Replacement for __del__

2009-05-19 Thread Alan Gauld
del__(self): try: os.remove(self.lockname) except: pass Of course the question of whether using disk storage to indicate object lifetime is a good design pattern is another issue altogether! -- Alan Gauld Author of the Learn to Program web site htt

Re: [Tutor] clean text

2009-05-19 Thread Alan Gauld
find any you can loop over the instances using replace() or sub() to change them. The translate module might even let you do all changes in one go. That should be faster I think. HTH -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/

Re: [Tutor] odbc connection with python

2009-05-19 Thread Alan Gauld
s probably your best bet. It includes a GUI builder and has strong links to databases. http://dabodev.com/ Caveat: I've only read the web pages, not used it! But it has had some good reviews on this list before. -- Alan Gauld Author of the Learn to Program web site http://w

Re: [Tutor] Iterating over list of functions

2009-05-20 Thread Alan Gauld
T' >>> funcs[2]('THIS IS A SIMPLE TEST') 'this is a simple test' -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] delphi, pascal and Python

2009-05-20 Thread Alan Gauld
"Andy Cheesman" wrote Is there a Method for wrapping delphi and/or pascal code into python like SWIG? I've googled to no avail, Can anyone help me? Try this: http://membres.lycos.fr/marat/delphi/python.htm Alan G ___ Tutor maillist - Tutor@

Re: [Tutor] Iterating over list of functions

2009-05-20 Thread ALAN GAULD
> understand exactly what you are saying and what you are advocating. > The 'dictionary of functions' is the 'best' approach because of simplicity > and because it minimizes chances or errors. Correct. Maintaining synch of indexes between two arrays of data items is always going to be a risky b

Re: [Tutor] delphi, pascal and Python

2009-05-21 Thread Alan Gauld
"Marc Tompkins" wrote Is there a Method for wrapping delphi and/or pascal code into python like SWIG? http://membres.lycos.fr/marat/delphi/python.htm That's a package to let you embed Python in Delphi; the OP wants to go the other direction. So it is, I didn't read the OP question clo

Re: [Tutor] sqlite3 format data from tables

2009-05-23 Thread Alan Gauld
hon v3 the even more powerful new formatting features there) self.menu[5]=("Transaction History",self.display_transactions) Can I use the numbers 1,2,3,4 as a way to return the history? I don;t really understand what you mean by this bit? -- Alan Gauld Author of the Learn to Program web si

Re: [Tutor] need help opening a file in idle

2009-05-24 Thread Alan Gauld
tely not getting the point? It's up to you to know where the file is and tell Python. You might try this to find out where Python is looking for the file by default. import os print os.getcwd() Which prints what Python considers the Current Working Directory. You will find a lot more on this

Re: [Tutor] A few very basic questions

2009-05-24 Thread Alan Gauld
y have to set up some paths in Eclipe's preferences. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Find a good linux distribution with python.

2009-05-24 Thread Alan Gauld
;t do it in advance just add to it as you need to. On the other hand, any code I might write would be difficult for others to use. If you stick to the a standard Python package tools it should be fine. Not just on Linux but on any other OS too. -- Alan Gauld Author o

Re: [Tutor] Search for hex data in file

2009-05-25 Thread Alan Gauld
exactly what kind of data you are dealing with. What do you guys recommend? I want to search the file for certain hex value and get the byte offset within the file. It might help if you posted some code too. And tell us what happens when you run it, and why that was not what you wanted to happe

Re: [Tutor] ?????

2009-05-25 Thread Alan Gauld
"prasad rao" wrote for x in dir(sys): ?? if sys.x is callable: Even if you use the other suggestions to prove its callable that doesn't mean you can do this: print sys.x() If the callable takes parameters then this will fail. You need to know quite a lot more about what you are

Re: [Tutor] A few very basic questions

2009-05-25 Thread Alan Gauld
"M Tramp" wrote the packages I needed. Fink appeared to be installing them fine with little interaction from me. I ran Eclipse again, but it still burps on: import gtk Have you installed pygtk? You need both pygtk and gtk. The former uses the latter. Alan G ___

Re: [Tutor] Can't print a string, gives me syntax error

2009-05-25 Thread Alan Gauld
"xbmuncher" wrote I ran this in IDLE: t = 'hi' print t SyntaxError: invalid syntax (, line 1) I've also tried this as sample.py : import string text = 'hello world' print text It gives me a syntax error on "print text" line Looks like you are using Python v3. Most tutorials are stil

Re: [Tutor] A few very basic questions

2009-05-26 Thread Alan Gauld
"M Tramp" wrote You need both pygtk and gtk. The former uses the latter. Yes. It is. I went back and installed more. Still I get the error: "No module named gtk" So I'm back to -- or nearly so -- my original question. Where on my hard drive should these libraries reside? I'm suspect

Re: [Tutor] Tinkering with Tkinter

2009-05-26 Thread Alan Gauld
hing happens. Don't worry too much, just enter the code and run it. If you do want to use the >>> prompt to experiment use an OS command line window rather than an IDE. In pratice when working with Tkinter I've leaned not to trust any IDE but just use it as a text editor. I type

Re: [Tutor] Python Function Doubt

2009-05-26 Thread Alan Gauld
confusing situation with mutable types that Dave referred to. If the function changes a parameter value and it is mutable then the original object is changed. If it is immutable a new object is assigned to the parameters name. HTH, -- Alan Gauld Author of the Learn to Program web site http:

Re: [Tutor] writing HTML code to a variable/file

2009-05-26 Thread Alan Gauld
gt;" + lastName + ", " + firstName + "" But IMHO its much easier to use string formatting: aVar = 'http://users.example.com/~%s>%s,%s' %( userName,lastName,firstName) Its also more efficient. However in practice you don;t need to store it as a variab

Re: [Tutor] IDLE shortcut doesn't exist except for in the Start Menu

2009-05-26 Thread Alan Gauld
"Gregory Morton" wrote Looking in the directory for Python, I see no real sign of IDLE anywhere in it. Look at the properties of the start menu item. It should show the shortcut points to something like: C:\Python25\Lib\idlelib\idle.pyw Is there any logic behind why I can't access IDLE wi

Re: [Tutor] IDLE shortcut doesn't exist except for in the Start Menu

2009-05-27 Thread ALAN GAULD
> Strangely, the shortcut properties don't show the target. On my > Windows XP system, the properties just show > Target type: Application > Target location: (blank) > Target: Python 2.6.1 > > Kent Bizarre! My XP box says Target type: PYW File Target location: idlelib Target: C:\Python25\Lib

Re: [Tutor] Getting exposure to high quality Python code

2009-05-27 Thread Alan Gauld
f examples. Finally look at the ActiveState web site for Python recipes. Lots of good ideas there. Of course what constitutes good code is somewhat subjective but the library and recipes are virtually all pretty good code IMHO. -- Alan Gauld Author of the Learn to Program web site http://www.al

Re: [Tutor] Displaying range in 3.0.1

2009-05-28 Thread Alan Gauld
"Gregory Morton" wrote I've been reading this Python 3.0.1 tutorial(http://docs.python.org/3.0/tutorial/controlflow.html), Looks like a bug in the tutorial! In Python 3 you cannot just print a range it is now a generator. Notice that in the tutorial the range() calls are not shown at the >

Re: [Tutor] Mapping to an equivalent / similar object?

2009-05-28 Thread Alan Gauld
. But since the supplier is chosen from external factors the Flavor doesn't need to know about its supplier. And the supplier only needs to know about how to query a flavour. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ __

Re: [Tutor] creating interactive program with python

2009-05-28 Thread Alan Gauld
iously but those that do seem to find it works OK. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] how to get variable from an external script or program

2009-05-29 Thread Alan Gauld
"vince spicer" wrote import commands output = commands.getout("ls -lah") There are many ways to do this in Python including os.popen, commands and subprocess. But subprocess is the "officially correct" version, the others are deprecated and could theoretically disappear in a future ver

Re: [Tutor] (no subject)

2009-05-30 Thread Alan Gauld
en go back to the top for the next number to test. You will find more about loops in the Loops topic of my tutorial. HTH -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Docking Windows using Python

2009-05-30 Thread Alan Gauld
you will have to do quite a lot of programming to make it work, probably defining your own custom widget. That's a lot of work. Your best bet is to ask the question on the various toolkit specific forums and mailing lists since there will likely be people who have done it already. HTH, -- Alan

Re: [Tutor] Using a list

2009-05-30 Thread Alan Gauld
s[1]=dexterity=+change points=points-change if allot=='str': change=int(raw_input('How many points do you wish to allot? ')) attributes[3]=strength=+change And this gets even more messy. Again think how it would look with a dictionary... -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Why does it display traceback info here and not there?

2009-05-30 Thread Alan Gauld
ans there is an error so turning the messages off won't help your program to run, you just won't get any clues as to why its not working! HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Class Tips

2009-05-30 Thread Alan Gauld
arger programs than this. But as an example of using a class its nearly OK, just the tweak of the return value to think about - and that applies to the function version too! -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ _

Re: [Tutor] String formatting hex numbers

2009-05-30 Thread Alan Gauld
t;HEX:%s" % hex(-29) 'HEX:-0x1d' And all is as expected. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Why does it display traceback info here and not there?

2009-05-31 Thread Alan Gauld
"xbmuncher" wrote I'd like to use notepad++ to execute the scripts I edit, is there a way to solve this problem? Thats really a question for Notepad++ users! You might be able to use a shortcut to Notepad++ and change that Startup folder to be the one where your python scripts live? Beyond

Re: [Tutor] converting xls to csv

2009-05-31 Thread Alan Gauld
e location of the problem! - is in the earlier lines. However taking a wild guess - are you using Python v3? print "-- beginning to convert XLS to CSV --" If so print is now a function so you need to surround the string with () But if you are not using v3, then please s

Re: [Tutor] Class Tips

2009-05-31 Thread Alan Gauld
r a number!' You could put the whole thing in a while loop so the error gets printed but the user has a chance to corect it. def get_inputs(): while True: try: # blah blah return . # breaks from the while loop except ValueError,

Re: [Tutor] Sample python file/module templates?

2009-06-01 Thread Alan Gauld
thons help() function. Change logs are mostly kept in the version control tool, but you can access the svn repository onthe web site to see the history etc. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tuto

Re: [Tutor] Challenge supporting custom deepcopy with inheritance

2009-06-01 Thread Alan Gauld
quot; part of the copy on the result. As a minimum subclasses should adhere to the parent interface. Unfortunately because Python only allows a single constructor that can be a limiting factor :-( ( Multiple constructors (or factory methods) is one feature I would like to see added to Python! )

Re: [Tutor] Challenge supporting custom deepcopy with inheritance

2009-06-01 Thread Alan Gauld
"W W" wrote ( Multiple constructors (or factory methods) is one feature I would like to see added to Python! ) Wouldn't it be possible to create sort of a... bastardization? i.e. def __init__(self, *args): if len(args) == 0: #do something if len(args) == 1: #do somethin

Re: [Tutor] Challenge supporting custom deepcopy with inheritance

2009-06-01 Thread Alan Gauld
le(fn, cnt) But its two lines not one... :-( And so far as I know it has not been PEPd although I'm sure it has been discussed. -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.o

Re: [Tutor] Challenge supporting custom deepcopy with inheritance

2009-06-01 Thread Alan Gauld
"Kent Johnson" wrote But its two lines not one... :-( Why not this? class C: def __init__(self): pass @staticmethod def LoadFromFile(fname, count): c = C() # init c from the file return c and similar for Create(). Client code is one line: c = C.LoadFromFile(fn, cnt) Kent

Re: [Tutor] Challenge supporting custom deepcopy with inheritance

2009-06-01 Thread Alan Gauld
"Kent Johnson" wrote > We can fake the Delphi style by using a default constructor and then > just > calling the "constructors" after initialisation: > But its two lines not one... :-( Why not this? class C: def __init__(self): pass @staticmethod def LoadFromFile(fname, count): c

Re: [Tutor] Spell checking source code?

2009-06-01 Thread Alan Gauld
"Allen Fowler" wrote Are there any utilities to help "spell check" source code? (Docstrings, etc) I used to have an emacvs script that could do it for C/C++ using the vanilla Unix spell program. Unfiortunately I can't remember its name but a hunt around the e,macs web sites might throw up a

Re: [Tutor] Spell checking source code?

2009-06-02 Thread ALAN GAULD
> From: "wormina...@gmail.com" > To: Alan Gauld > Sent: Tuesday, 2 June, 2009 1:09:39 AM > Subject: Re: [Tutor] Spell checking source code? > > In vim, > > :set spell > :set nospell > :help spell But that will check the whole file. The OP only wanted

Re: [Tutor] Text.index()

2009-06-02 Thread Alan Gauld
ally some flags. Please read the documentation then ask some specific questions about what you don't understand. The Text widget is immensley powerful so you need to spend some time studying it to get the best out of it. -- Alan Gauld Author of the Learn to Program web site http://www.alan-

Re: [Tutor] python workspace

2009-06-02 Thread Alan Gauld
lues. Certainly IDLE, Pythonwin and Eclipse/PyDev can all do that. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] my first gui

2009-06-03 Thread Alan Gauld
entry2=Entry(frame3,relief='sunken',border=1) entry2.pack(side='left',fill='both') lable2=Label(frame3,text='modifide time',border=1) lable2.pack(side='left',fill='both') entry3=Entry(frame3,relief='sunken',border=1) entry

Re: [Tutor] serious problem with graphics module

2009-06-03 Thread Alan Gauld
"W W" wrote Do you (or sombody else) know how to get ipython working with Python 2.6 (you know, the Python release, which has that new turtle module ;-) ) doesn't install on my Windows box... other than that I've got no experience with it I thought the new turtle module could be made to

Re: [Tutor] array manipulations

2009-06-04 Thread Alan Gauld
f r[0] in d: d[r[0]].append(r[2]) ... else: d[r[0]] = [r[0],r[2]] ... new = [v for k,v in d.items()] new [['F1', 0.9, 0.5], ['f2', 0.6999]] There may be a more elegant way to handle the if/else but its too early to think of one :-) HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Python 2.2... os.exec catch stdout

2009-06-05 Thread Alan Gauld
en directly, it does not write onto the stdout stream. (I think if you switch to ex mode it does use stdout - but I may be wrong about that!) If vim is just an unfortunate example then it might be possible but I think we need to know a bit more about what exactly you are trying to do. -- Alan Gauld

Re: [Tutor] Python 2.2... os.exec catch stdout

2009-06-05 Thread ALAN GAULD
If vim is just an unfortunate example then it might be possible but I think we need to know a bit more about what exactly you are trying to do. > It's actually a stand alone program; which opens up a $EDITOR; an > then prints to stdout the results of some db munging. ... > what I'm wanting to g

Re: [Tutor] class design

2009-06-06 Thread Alan Gauld
ach class? Until we know what the cklasses are for its hard to know what you want improved... -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

<    6   7   8   9   10   11   12   13   14   15   >