[Tutor] Invitation to connect on LinkedIn
LinkedIn I'd like to add you to my professional network on LinkedIn. - Govind Accept Govind Agrawal's invite: https://www.linkedin.com/e/isd/738276939/KwugpKmr/ -- (c) 2009, LinkedIn Corporation ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] collecting certain data from a textfile
Hi! I got this simple but effective piece of code. It picks certain wanted pieces of data from a textfile based on database records and puts all of them them in a new textfile in certain order. I was wondering, could it be possible to make it otherwise in case that there's much more rows in that textfile and/or there's much more bits of data to collect? data = open('data.txt','r') f1 = data.readlines() data.close() f2 = open('data.txt','r') i=0 f3 = [] while i len(f1): a=f2.readline() b=f2.readline() c=f2.readline() data2 = ( a[1:38].strip()+';'+ a[54:88].strip()+';'+ b[77:96].strip()+';'+ b[1:16].strip()+';'+ c[23:33].strip()+';'+ c[123:133].strip()+';' ) wanted = (data2) f3.append(wanted + \n) i += 3 f4 = open('wanted.txt', 'w') f4.write(''.join(f3)) f2.close() f4.close() Thanks! OV ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Still Trying to Understand GAE
Hi Wesley! Thankyou very much for your mail (and i'd like to thankyou in a special way for your corrections :) ). it imports all sub*packages*. don't think directories because the import mechanism doesn't work this way. this is likely because there are __init__.py files in those subdirectories. another possibility is that there are non-empty __init__.py files that do the imports of things that you're not expecting. Ok, i've checked all those files, because in a standard python evinronment the __init__.py is the only file that can decide what to import. If you want to check directly, here you can find the SDK. Just open the google directory. http://googleappengine.googlecode.com/files/google_appengine_1.2.5.zip As i've said, this simple script: --- #!/usr/bin/python import google print Content-Type: text/html print print head print /head print body print google,dir(google) print /br print /br print /body --- Gives this output: google ['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'appengine', 'net', 'pyglib'] The google directoy has an empty __init__.py file (well, if we want to be completely correct it contains some commented -#- lines). Same for appengine, net and pyglib. As they all have an __init__.py file, they should be consiedered as modules from the python interpreter. So, if i run import google it imports all google's submodules. Well, now, the problem: if i create another directory (module) in the google dir, it doesn't get imported. Of course i've put in it some .py files and an empty __init__.py file. Thankyou again! Giorgio 2009/9/13 wesley chun wes...@gmail.com: hi Giorgio, welcome to Python (whether directly or from GAE!) :-) my comments below. with import i can import modules or single functions. And this is ok. not quite true. regardless of whether you use import or from-import, you're *always* importing (and loading) modules or packages in their entirety. now, whether you have *access* to entire modules/packages or individual attributes (functions, classes, or standard data), is another matter -- usually this is a result of using from-import. also, the difference between importing and loading is that loading only happens the first time you import a module/package. (if you do it more than once, e.g., module A imports B and C and module B also imports C, the import of C happens twice but the loading happens only once. if i use import google it also imports all subdirectories. And i can't understand wiìhy it does so. it imports all sub*packages*. don't think directories because the import mechanism doesn't work this way. this is likely because there are __init__.py files in those subdirectories. another possibility is that there are non-empty __init__.py files that do the imports of things that you're not expecting. hope this helps! -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Core Python Programming, Prentice Hall, (c)2007,2001 Python Fundamentals, Prentice Hall, (c)2009 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Invitation to connect on LinkedIn
I'm going to be charitable and assume this is a mistake. This is completely inappropriate to post to the tutor list. Kent On Tue, Sep 15, 2009 at 6:50 AM, Govind Agrawal govindgo...@gmail.comwrote: LinkedIn I'd like to add you to my professional network on LinkedIn. - Govind Accept Govind Agrawal's invite: https://www.linkedin.com/e/isd/738276939/KwugpKmr/ © 2009, LinkedIn Corporation ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Invitation to connect on LinkedIn
Gmail adds everyone you mail to your address book, and sites like LinkedIn ask for your email account credentials to search for contacts from your address book. I think this could happen to anyone who is unfamiliar with either service. Michael 2009/9/15 Kent Johnson ken...@tds.net I'm going to be charitable and assume this is a mistake. This is completely inappropriate to post to the tutor list. Kent On Tue, Sep 15, 2009 at 6:50 AM, Govind Agrawal govindgo...@gmail.comwrote: LinkedIn I'd like to add you to my professional network on LinkedIn. - Govind Accept Govind Agrawal's invite: https://www.linkedin.com/e/isd/738276939/KwugpKmr/ © 2009, LinkedIn Corporation ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- Michael Connors Burggravenlaan 148, Leiden 2313 HZ, The Netherlands 0031611520252 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Invitation to connect on LinkedIn
Kent Johnson wrote: I'm going to be charitable and assume this is a mistake. This is completely inappropriate to post to the tutor list. I assume -- having seen a few of these go past -- that such services say on joining: do you want me to email every one in your address book to ask them to link in with you (or be your friend, or whatever). Naive users will simply say: yes; here are the keys to my mailbox... and the result will be posts like these. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] New guy question...
First, let me say thanks for all the responses! This definitely looks like a useful mailing list for complete noobs like me. Second, I think my machine is probably set up a little weird. I have Python 2.6.2 installed alongside 3.1.1 so maybe that makes a difference. I'm writing programs in TextMate and running them from there. Which seemed to be working fine until I ran into this input issue. At any rate, I've installed 2.6.2 over again from a fresh download and I think I can move ahead. The example works now as long as I change input to raw_input. This should allow me to get through some more of this tutorial book anyway. Thanks again, all! I appreciate the help. - Warren (war...@wantonhubris.com) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] PyInit__tkinter fails with UnicodeEncodeError
Hi, I have a standalone python executable created using PyInstaller (modified to support Python 3) on Linux. This executable was running well with Python 3.0.1. But on Python 3.1.1 it is breaking with UnicodeEncodeError. Executable created with same code on Windows it is running without any error. After debugging the Python code I found that the PyInit__tkinter in file _tkinter.c is not able to encode the executable name or path when it finds characters other than 'a' ('A') through 'p' ('P') at position multiple of 4 (0 based). For example if my executable name is setup it finds 's' at the position 0 and breaks with UnicodeEncodeError. NOTE: If I change the name to etup (removed 's') it is executing well. And also if I replace 's' with any character 'a' through 'p' it is working. This is happening because here by default 'strict' error handler is being used. I tried to play a little with the Python code. And modified PyInit__tkinter() to used surrogatepass error handler while it is encoding the Unicode string with utf-8 encoding. i.e. I replaced cexe = PyUnicode_AsEncodeString(uexe,Py_FileSystemDefaultEncoding,NULL); with cexe = PyUnicode_AsEncodeString(uexe,Py_FileSystemDefaultEncoding, surrogatepass); My executable started running without changing its name. I have no idea whether this is a feature or bug in PyInit__tkinter(). Is there any way I can specify PyInit__tkinter to use surrogatepass instead of strict error handler. Please help me with your suggestions. Thanks, Lakshman Please do not print this email unless it is absolutely necessary. The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. www.wipro.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] New guy question...
On Tue, Sep 15, 2009 at 9:07 AM, Warren war...@wantonhubris.com wrote: Second, I think my machine is probably set up a little weird. I have Python 2.6.2 installed alongside 3.1.1 so maybe that makes a difference. That should be fine. I'm writing programs in TextMate and running them from there. Which seemed to be working fine until I ran into this input issue. Does TextMate support input into a running Python program? I'm not sure if it supports standard input. You might have to run the program from Terminal to get this to work. Kent ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] New guy question...
Does TextMate support input into a running Python program? I'm not sure if it supports standard input. You might have to run the program from Terminal to get this to work. Good question, Kent. That might be the root of all of this pain. I'll experiment when I get a chance... - Warren (war...@wantonhubris.com) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] collecting certain data from a textfile
Olli Virta wrote: Hi! I got this simple but effective piece of code. It picks certain wanted pieces of data from a textfile based on database records and puts all of them them in a new textfile in certain order. I was wondering, could it be possible to make it otherwise in case that there's much more rows in that textfile and/or there's much more bits of data to collect? Otherwise is always possible! What is the problem? Why do you want it otherwise? data = open('data.txt','r') f1 = data.readlines() data.close() There is no need to do the above! You don't need a line count to control the loop. f2 = open('data.txt','r') Drop next lline: i=0 f3 = [] Change next two lines: while i len(f1): a=f2.readline() To: while True: a=f2.readline() if not a: break b=f2.readline() c=f2.readline() data2 = ( a[1:38].strip()+';'+ a[54:88].strip()+';'+ b[77:96].strip()+';'+ b[1:16].strip()+';'+ c[23:33].strip()+';'+ c[123:133].strip()+';' ) wanted = (data2) If you are concerned about enough memory, write data2 to the file instead of collecting in a list. f3.append(wanted + \n) Drop next line: i += 3 f4 = open('wanted.txt', 'w') f4.write(''.join(f3)) f2.close() f4.close() -- Bob Gailer Chapel Hill NC 919-636-4239 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Image manipluation (On-the-fly thumbnail creation)
I've recently delved into python, about a week or so ago; I'm trying to figure out how to create on-the-fly thumbnails. Are there python standard library modules I could/should use or should I use external libraries like: GD, Gimp, or ImageMagick? -- View this message in context: http://www.nabble.com/Image-manipluation-%28On-the-fly-thumbnail-creation%29-tp25456792p25456792.html Sent from the Python - tutor mailing list archive at Nabble.com. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Image manipluation (On-the-fly thumbnail creation)
On Tue, Sep 15, 2009 at 10:03 AM, dan06 dan.king...@yahoo.com wrote: I've recently delved into python, about a week or so ago; I'm trying to figure out how to create on-the-fly thumbnails. Are there python standard library modules I could/should use or should I use external libraries like: GD, Gimp, or ImageMagick? -- View this message in context: http://www.nabble.com/Image-manipluation-%28On-the-fly-thumbnail-creation%29-tp25456792p25456792.html Sent from the Python - tutor mailing list archive at Nabble.com. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor check out: http://www.pythonware.com/products/pil/ creating thumbnail example here http://www.pythonware.com/library/pil/handbook/image.htm Vince ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Image manipluation (On-the-fly thumbnail creation)
import glob import Image for infile in glob.glob(*.jpg): im = Image.open(infile) # converting to thumbnail image im.thumbnail((128, 128), Image.ANTIALIAS) im.save(thumb + infile, JPEG) Will this be of ur help Vince? On 15/09/2009, vince spicer vinces1...@gmail.com wrote: On Tue, Sep 15, 2009 at 10:03 AM, dan06 dan.king...@yahoo.com wrote: I've recently delved into python, about a week or so ago; I'm trying to figure out how to create on-the-fly thumbnails. Are there python standard library modules I could/should use or should I use external libraries like: GD, Gimp, or ImageMagick? -- View this message in context: http://www.nabble.com/Image-manipluation-%28On-the-fly-thumbnail-creation%29-tp25456792p25456792.html Sent from the Python - tutor mailing list archive at Nabble.com. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor check out: http://www.pythonware.com/products/pil/ creating thumbnail example here http://www.pythonware.com/library/pil/handbook/image.htm Vince -- || a j i t || ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Image manipluation (On-the-fly thumbnail creation)
dan06 wrote: I've recently delved into python, about a week or so ago; I'm trying to figure out how to create on-the-fly thumbnails. Are there python standard library modules I could/should use or should I use external libraries like: GD, Gimp, or ImageMagick? When I needed thumbnails of my images, I created them using ImageMagick. ImageMagick is a very nice tool for editing images and since it is called from the command line it is easy to invoke it from a programming language. There are python-bindings for it, but I think they are not very actively maintained and so I wouldn't use them. Using PIL is another option and maybe more pythonic, but if you are familiar with ImageMagick it might be a good alternative. - Patrick ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Wordscramble.py
This is my first Python project. I am doing this to help me learn the language. I was wondering if someone could give me some advice as I have a lot of questions. 1. I would like to have someone look over the code and tell me how to improve it. I am sure that a lot of it can be done better than the way that I have it written. Is anyone that would be willing to do this? 2. Although it works as is I would like some advice on improving it. ie. Making it look better, play better, etc. 3. I switched from Windows to Linux about 2 months ago. I read that Python is a cross platform language. What would need to be done to make this program run in windows too? 4. Once it is finished, I would like to make it installable for people other than programmers. How? These are a few of the things that I would like to accomplish. The code can be found at pastebin.com: http://pastebin.com/m1ab9a734 Wordscramble.py http://pastebin.com/d2686ec4scrmod.py http://pastebin.com/m4f611e0c wordlist.py ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] New guy question...
2009/9/15 Warren war...@wantonhubris.com: Does TextMate support input into a running Python program? I'm not sure if it supports standard input. You might have to run the program from Terminal to get this to work. Good question, Kent. That might be the root of all of this pain. I'll experiment when I get a chance... - Warren (war...@wantonhubris.com) ___ Tutor maillist - tu...@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor As I mentioned in my earlier response, the only way I could replicate the error was to pipe the file into python, disconnecting (I'm guessing) the stdin stream from the terminal: $ cat test.py input() $ cat test.py | python3 Traceback (most recent call last): File stdin, line 1, in module EOFError: EOF when reading a line (I also tested the script in the OP, and got identical output to that mentioned). This supports Kent's suggestion in a way, although maybe for a slightly different reason. -- Rich Roadie Rich Lovely There are 10 types of people in the world: those who know binary, those who do not, and those who are off by one. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] breaking out of a function that takes too long
Hey everyone, Is there a way to break out of a function if it exceeds a certain time limit for execution? There's a Website I'm scraping on a regular basis, and for some reason that I can't divine the site has radically varying response times. In some cases, I get a result vary quickly; at other times, my entire program hangs because of this one call to an external source. Even more strange, if I quit the scrape when it appears to hang and then try it again a few moments later, it will sometimes work just fine (sometimes being the key word). I'm not certain, but I'm guessing this inconsistent behavior has something to do with the site that I'm scraping. So again, is there a way to place a time limit on the execution of a function, after which you can break out of it and then retry it or move along with the rest of your program? TIA, Serdar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] breaking out of a function that takes too long
Serdar Tumgoren zstumgo...@gmail.com wrote Is there a way to break out of a function if it exceeds a certain time limit for execution? Yes, you can put the call in a thread then in the main thread start a timer. If the timer expuires before the thread returns kill the thread.thread There's a Website I'm scraping on a regular basis, and for some reason that I can't divine the site has radically varying response times. Could be a lot of people have written scrapers and they all schedule them to run at reulat intervals... If the clocks all suddenly align you will get a massive demand on the server (its effectively like a denial of service attack on the server!). Or it could even be real users if it happens when some significant change occurs - like stock/share price web sites often get big peaks at market open and close times. try it again a few moments later, it will sometimes work just fine (sometimes being the key word). I'm not certain, but I'm guessing this inconsistent behavior has something to do with the site that I'm scraping. It could be anywhere in your network connection, including your ISP. If its a local operator there may be peak periods when people go online based on local patterns of usage, especially if its ot a big company - they might only have a couple of 2M pipes say to the core network. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] breaking out of a function that takes too long
On Tue, Sep 15, 2009 at 5:02 PM, Serdar Tumgoren zstumgo...@gmail.com wrote: Hey everyone, Is there a way to break out of a function if it exceeds a certain time limit for execution? In general this is tricky. It usually involves setting up another thread to run or monitor the function, then somehow terminating the thread if it runs too long. In your case, it sounds like a better solution is to set a socket timeout. At the beginning of your program - before attempting any access to the website - put import socket socket.setdefaulttimeout(timeout in seconds) This will cause the web site fetch to fail by raising socket.timeout if the fetch blocks for longer than the timeout seconds. Kent ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] breaking out of a function that takes too long
Most socket request libraries have timeouts on connection attempts, have you looked into that already? On Tue, Sep 15, 2009 at 4:02 PM, Serdar Tumgoren zstumgo...@gmail.comwrote: Hey everyone, Is there a way to break out of a function if it exceeds a certain time limit for execution? There's a Website I'm scraping on a regular basis, and for some reason that I can't divine the site has radically varying response times. In some cases, I get a result vary quickly; at other times, my entire program hangs because of this one call to an external source. Even more strange, if I quit the scrape when it appears to hang and then try it again a few moments later, it will sometimes work just fine (sometimes being the key word). I'm not certain, but I'm guessing this inconsistent behavior has something to do with the site that I'm scraping. So again, is there a way to place a time limit on the execution of a function, after which you can break out of it and then retry it or move along with the rest of your program? TIA, Serdar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] breaking out of a function that takes too long
Thanks to all for the responses. I've never used threading, but from some initial googling it appears that it can indeed by tricky and there seem to be numerous recommendations against killing threads or processes. I'll explore the socket request libraries mentioned by several to see if that does the trick. Many thanks! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Wordscramble.py
kreglet wrote: This is my first Python project. I am doing this to help me learn the language. I was wondering if someone could give me some advice as I have a lot of questions. 1. I would like to have someone look over the code and tell me how to improve it. I am sure that a lot of it can be done better than the way that I have it written. Is anyone that would be willing to do this? 2. Although it works as is I would like some advice on improving it. ie. Making it look better, play better, etc. 3. I switched from Windows to Linux about 2 months ago. I read that Python is a cross platform language. What would need to be done to make this program run in windows too? 4. Once it is finished, I would like to make it installable for people other than programmers. How? These are a few of the things that I would like to accomplish. The code can be found at pastebin.com: http://pastebin.com/m1ab9a734 Wordscramble.py http://pastebin.com/d2686ec4scrmod.py http://pastebin.com/m4f611e0c wordlist.py I got it to work on linux but first had to use dos2unix to remove the ^M. I am new to programing myself so can not be of much help but to make it a python program I have used distutils; http://wiki.python.org/moin/Distutils/Tutorial Now to get it cross platform I have no idea. -david -- Powered by Gentoo GNU/Linux http://linuxcrazy.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Parsing html tables and using numpy for subsequent processing
Hello all, I've finally gotten around to my 'learn how to parse html' project. For those of you looking for examples (like me!), hopefully it will show you one potentially thickheaded way to do it. For those of you with powerful python-fu, I would appreciate any feedback regarding the direction I'm taking and obvious coding no-no's (I have no formal training in computer science). Please note the project is unfinished, so there isn't a nice, neat result quite yet. Rather than spam the list with a long description, please visit the following post where I outline my approach and provide necessary links -- http://financialpython.wordpress.com/2009/09/15/parsing-dtcc-part-1-pita/ The code can be found at pastebin: http://financialpython.pastebin.com/f4efd8930 The original html can be found at http://www.dtcc.com/products/derivserv/data/index.php (I am pulling and parsing tables from all three sections). Many thanks! -- DK ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor