Re: [Tutor] TEST to see if this gets out
On Fri, 2 Sep 2005, Jack Anema wrote: TEST Hi Jack, We're here. Do you have a question about learning Python? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python2.3.4, PySqlite2 and Solaris
On 9/1/05, Luis N [EMAIL PROTECTED] wrote: Hi, After fighting with installing pysqlite2 Apologizes, I started over. It went much better the second time. bash-2.05$ test-pysqlite .. -- Ran 142 tests in 0.672s Luis ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python2.3.4, PySqlite2 and Solaris
Python 2.3.4 (#1, Aug 23 2004, 13:59:34) [GCC 3.2.3] on sunos5 Type help, copyright, credits or license for more information. from pysqlite2 import dbapi2 as sqlite Traceback (most recent call last): File stdin, line 1, in ? File /home/rbnewby/lib/python/pysqlite2/dbapi2.py, line 32, in ? from pysqlite2._sqlite import * ImportError: ld.so.1: python: fatal: relocation error: file /home/NaN/lib/python/pysqlite2/_sqlite.so: symbol sqlite3_libversion: referenced symbol not found Hi Luis, This means that Python can physically find a 'sqlite' library, but that what it had found does not appear to be compatible with the version that the pysqlite module expects. Is it possible that you have an older version of sqlite? You may also want to send your question to the pysqlite mailing list. We on Python-Tutor probably aren't that familiar with pysqlite installation. You may be able to get better help from the pysqlite folks: http://lists.initd.org/mailman/listinfo/pysqlite ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Batch file to detect if Python is installed
Dear Omniscient List, Does anyone know of a cunning method to detect whether Python is installed using a batch file? I'd like a batch file to execute an .exe if Python IS NOT installed, and execute a .py if Python IS installed. This is my first foray into the disturbing world of windows batch files, and I don't like it very much. Thanks in advance, Tom P.S. I do realise this is a little off topic... It does involve Python and programming... just not programming in Python. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] FIREWALLS
I used python several months ago to write a simple program now i went back to use it to rewrite the same program and when I try to run it it says that my firewalls may be to secure. everytime the program runs in python it restarts and just has empty lines. how do I change my firewalls to be able to run a program in python? I have tried using different versions of python ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
What does [sic] mean? I see it all the time. June Bakersfield, California Dear June: Us too. We always wondered why these three little letters appear next to misspellings and other mistakes. As with many grammatical issues, we learned that Latin is to blame. Sic is Latin for thus. Yeah, that didn't clear it up for us either. But apparently, since the 1880s, writers have used [sic] next to quotations that include errors. This little notation means, Hey, I know this quote looks wrong, but it was that way when I found it, so don't blame me. Maybe the original text used archaic spelling or the original writer just messed up. But the person who's quoting that text is aware of the earlier mistake and wants you to know it. [Sic] is shorthand for all that, at least to scholarly types. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Directory permission and ACLs
I am new to python and wanted to write a program that looks at directory permissions and ext3 ACLs and also change them if needed. What modules would I be looking at for those functions? Thank you. Pat ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] convert binary to ascii
Hello List it has been a long time. Here is my question : sam in binary is 01110011 0111 01101101. if given 01110011 0111 01101101 how would I go back to ascii. I guess am asking is there a module that will do this conversion for me. I have looked at binascii but have been up able to found a good example to work from. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Problem building Python on HP-UX
I'm trying to build Python 2.4.1 on HP-UX 11.00 with full tcl/tk IDLE support. So far, I haven't had any luck. I always wind up getting errors of the form: ld: DP relative code in file /ptg/devtools/hppa1.1/pre/lib/libtk8.4.a(tkWindow.o) - shared library must be position independent. Use +z or +Z to recompile. I have tried building tcl/tk without any configure options as well as with --disable-shared and --disable-load but this doesn't help. Anyone seen anything like this or know how to get around it? Jeff ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Directory permission and ACLs
On 9/2/05, Pat Martin [EMAIL PROTECTED] wrote: I am new to python and wanted to write a program that looks at directory permissions and ext3 ACLs and also change them if needed. What modules would I be looking at for those functions? os and os.path: * http://docs.python.org/lib/module-os.html * http://docs.python.org/lib/module-os.path.html stat and shutil might be useful too. HTH. -- Regards, Travis Spencer ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] FIREWALLS
I used python several months ago to write a simple program now i went back to use it to rewrite the same program and when I try to run it it says that my firewalls may be to secure. everytime the program runs in python it restarts and just has empty lines. how do I change my firewalls to be able to run a program in python? I have tried using different versions of python ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] convert binary to ascii
On Fri, 2 Sep 2005, Servando Garcia wrote: Here is my question : sam in binary is 01110011 0111 01101101. if given 01110011 0111 01101101 how would I go back to ascii. Hi Servando: If we have strings of ones and zeros, we can turn those into numbers by using the int() function. For example: ## int(101, 2) 5 int(110, 2) 6 int(111, 2) 7 ## For more information on int(), see: http://www.python.org/doc/lib/built-in-funcs.html#l2h-39 There is also a function to convert ordinals back into their ascii character values. Take a look at: http://www.python.org/doc/lib/built-in-funcs.html and search for the word ASCII: you should see a function there that will help. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] convert binary to ascii
On 9/2/05, Servando Garcia [EMAIL PROTECTED] wrote: Hello Hey Servando, Here is my question : sam in binary is 01110011 0111 01101101. if given 01110011 0111 01101101 how would I go back to ascii. I guess am asking is there a module that will do this conversion for me. I don't know about module, but it isn't hard to do it yourself. Here is one way: #!/bin/env python import sys for line in sys.stdin: result = for binaryStr in line.split(): j = len(binaryStr) - 1 i = charCodeOfBinaryStr = 0 while j 0: charCodeOfBinaryStr += int(binaryStr[j]) * 2 ** i j -= 1 i += 1 result += chr(charCodeOfBinaryStr) print result Here is the output of your binary string: $ python btoa.py 01110011 0111 01101101 sam Its a really common algorithm. Google for change of base algorithm and you'll probably find lots of explinations. HTH. -- Regards, Travis Spencer ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Batch file to detect if Python is installed
Does anyone know of a cunning method to detect whether Python is installed using a batch file? Search the registry using the reg command: -- DOS session - C:\WINDOWSreg query hkcu\software\Pytho Error: The system was unable to find the specified registry key or value C:\WINDOWSreg query hkcu\software\Python ! REG.EXE VERSION 3.0 HKEY_CURRENT_USER\software\Python C:\WINDOWS - Next question - How to detect that you got a result other than an error? Use ERRORLEVEL ERRORLEVEL will return 0 if the last command had no errors or an error number otherwise. Thus something like: @ECHO OFF reg query hkcu\software\Python if ERRORLEVEL 1 GOTO NOPYTHON python myscrip.py ... GOTO :EOF :NOPYTHON REM use dos commands here P.S. I do realise this is a little off topic... It does involve Python and programming... just not programming in Python. Seems relevant to me... BUT if you can be sure Windows Host Scripting is installed ands active that is much much easier to use... Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] convert binary to ascii
On 9/2/05, Danny Yoo [EMAIL PROTECTED] wrote: Hey Danny, If we have strings of ones and zeros, we can turn those into numbers by using the int() function. For example: ## int(101, 2) 5 int(110, 2) 6 int(111, 2) 7 Oh, that's nice. I guess my solution was the total C hacker's way; not very pythonic :-) Thanks for the info. -- Regards, Travis Spencer ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] mod_python.publisher
I'm having an issue with mod_python.publisher, supposedly i should be able to just place this code def index(): return "This is only a test." into test.py and when placed into my browser it should run the index function by default, but instead i get a 404 error. i'm running Apache/1.3.33 (Unix) mod_python/2.7.11 Python/2.2.3 -Scott Oertel ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] FIREWALLS
I used python several months ago to write a simple program now i went back to use it to rewrite the same program and when I try to run it it says that my firewalls may be too secure. Are you using IDLE? THe latest versions of IDLE issue a warning of this type. What happens if you just run your program from the OS commamd line? and just has empty lines. how do I change my firewalls to be able to run a program in python? I have tried using different versions of python If its not in IDLE then it will depend on what your program is doing. Can you post the error message? And if its not too long the code too? It saves us from guessing... :-) Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] mod_python.publisher
Scott Oertel wrote: I'm having an issue with mod_python.publisher, supposedly i should be able to just place this code def index(): return "This is only a test." into test.py and when placed into my browser it should run the index function by default, but instead i get a 404 error. i'm running Apache/1.3.33 (Unix) mod_python/2.7.11 Python/2.2.3 -Scott Oertel ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Just for fun i decided to upgrade the python version to 2.4.1 Apache/1.3.33 (Unix) mod_python/2.7.11 Python/2.4.1 mod_gzip/1.3.26.1a mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 FrontPage/5.0.2.2635 mod_ssl/2.8.22 OpenSSL/0.9.7a PHP-CGI/0.1b still no luck =( ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Sort a Set
How about this? Not only does it count each element, but you can also get a sorted set without using set! a = [24,24,24,16,16,15,15] b = {} for i in a: try: b[i] += 1 except KeyError: b[i] = 1 print b li = b.keys() print li li.sort() print li li.reverse() print li has output {24: 3, 16: 4, 15: 2} [24, 16, 15] [15, 16, 24] [24, 16, 15] Respectfully, Jacob Schmidt - Original Message - From: Jonas Melian [EMAIL PROTECTED] To: tutor@python.org Sent: Tuesday, August 23, 2005 8:25 AM Subject: [Tutor] Sort a Set I get a list of repeated numbers [24, 24, 24, 16, 16, 15, 15 ] Is possible get it without repeated numbers, without using set()? If I use set, then the list is unsorted and i cann't sorting it. For get the values i use: [x[0] for x in cardTmp] or: from itertools import imap for i in imap(lambda x: x[0], cardTmp): print i A idea it would be create a generator that will return elements one by one, and then it would be possible know if that element is in the new list. But generators are in 2.4 Python 2.3.5 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Counting help
I'll do this again, just because I like sending email. Very similar to Alan G.'s -- but with the do first, ask forgiveness later a = [Joe Smith, Joe Smith, Jack Smith, Sam Love, Joe Smith] b = {} for x in a: try: b[x] += 1 except KeyError: b[x] = 1 Access count like this, of course, b[Joe Smith] 3 Jacob Schmidt - Original Message - From: Scott Oertel [EMAIL PROTECTED] To: Tutor@python.org Sent: Tuesday, August 23, 2005 1:01 PM Subject: [Tutor] Counting help I have extracted a list of names, i.e. Joe Smith Joe Smith Jack Smith Sam Love Joe Smith I need to be able to count the occurances of these names and I really don't have any idea where to begin. Any ideas? excuse me this is my first post to this list, I hope I included enough information. -Scott Oertel ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] re.findall(), but with overlaps?
A friend of mine got bitten by an expectations bug. he was using re.findall to look for all occurances of strings matching a pattern, and a substring he *knew* was in there did not pop out. the bug was that it overlapped another matching substring, and findall only returns non-overlapping strings. This is documented; he just missed it. But he asked me, is there a standard method to get even overlapped strings? Cut to its basics, here's an artificial example: import re rexp=re.compile(B.B) sequence=BABBEBIB rexp.findall(sequence) ['BAB', 'BEB'] What he would have wanted was the list ['BAB', 'BEB', 'BIB']; but since the last 'B' in BEB is also the firt 'B' in BIB, BIB is not picked up. After looking through the docs, I couldn't find a way to do this in standard methods, so I gave him a quick RYO solution: def myfindall(regex, seq): ...resultlist=[] ...pos=0 ... ...while True: ... result = regex.search(seq, pos) ... if result is None: ... break ... resultlist.append(seq[result.start():result.end()]) ... pos = result.start()+1 ...return resultlist ... myfindall(rexp,sequence) ['BAB', 'BEB', 'BIB'] But just curious; are we reinventing the wheel here? Is there already a way to match even overlapping substrings? I'm surprised I can't find one. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Generate 8 digit random number
Hey Tutors I saw a lot of responses...After analyze them I have resumed two approaches 1.- Generate a random number from 0 to and fill this number with zeros (Almost everyone's approach) 2.- Generate 8 random numbers and join them (Pietro and someone else) Which one of this is more randomic? I mean which one of these has lower chances to get duplicates? Until now I'm using approach number 2...Unless anyone has something against it... Frankly, I would probably prefer #1 because it's probably faster. (You're just generating one number, and calling 1or 2 functions on it as opposed to at least 1 random and 1 function for each digit) Secondly, in both cases, there is the chance that you will get duplicates~~ So the best way to do that is save passwords already generated in a list. ## Try this ### import random import cPickle ## This is to save passwords already generated between program runs. def getlist(): try: fileobj = file(passwords.lst,r) returnlist = cPickle.load(fileobj) fileobj.close() except IOError: returnlist = [] return returnlist def generate(): return str(random.randrange(0,)).zfill(8) ## Not that this is the best, but it is concise def close(li): obj = file(passwords.lst,w) cPickle.dump(li,obj) obj.close() masterlist = getlist() num = 0 while 1: while num in masterlist: num = generate() masterlist.append(num) print num m = raw_input() if m == 'quit': close(masterlist) break ## Okay, I believe it will work, I haven't tested it though. Any problems, grouch at me, please. Respectfully, Jacob ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Print Output Location in Windows XP
Up until now I have been running my Python programs in Linux. I just wrote one in Windows XP and I can't find the print output. The Python program has a print statement, and when I run the program a black window opens and I can see printing going on. However, when it's finished printing, the output window closes. How do I get the output window to stay open, or where is the output stored? Thanks! Tom Strickland ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Print Output Location in Windows XP
On Sat, 2005-09-03 at 03:30 +0100, Tom Strickland wrote: How do I get the output window to stay open, or where is the output stored? You can open up a command prompt before running the program, which will allow you to see the output as the program runs. You get to this by 'Start Run..' or something similar. As you're using XP, you then type in 'cmd' which should bring up a command line. Navigate your way to the appropriate place and run the program. Alternatively, you could dump the output into a text file, but I have no idea how to do that in Windows so someone else'll have to pick that up for you. Hope that helps, Dan ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Print Output Location in Windows XP
Tom Strickland napsal(a): Up until now I have been running my Python programs in Linux. I just wrote one in Windows XP and I can't find the print output. The Python program has a print statement, and when I run the program a black window opens and I can see printing going on. However, when it's finished printing, the output window closes. How do I get the output window to stay open, or where is the output stored? You could: * put raw_input() statement on the last line in your program * run python with -i argument . i means stay interactive after run. example : python -i myfile.py Hope this helps -- geon ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Print Output Location in Windows XP
Something I do is like raw_input(\n\nPress enter to exit.) at the end, this works if all you want to do is see the text on the screen. Tom Strickland wrote: Up until now I have been running my Python programs in Linux. I just wrote one in Windows XP and I can't find the print output. The Python program has a print statement, and when I run the program a black window opens and I can see printing going on. However, when it's finished printing, the output window closes. How do I get the output window to stay open, or where is the output stored? Thanks! Tom Strickland ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] re.findall(), but with overlaps?
Terry Carroll wrote: But he asked me, is there a standard method to get even overlapped strings? After looking through the docs, I couldn't find a way to do this in standard methods, so I gave him a quick RYO solution: def myfindall(regex, seq): ...resultlist=[] ...pos=0 ... ...while True: ... result = regex.search(seq, pos) ... if result is None: ... break ... resultlist.append(seq[result.start():result.end()]) ... pos = result.start()+1 ...return resultlist ... myfindall(rexp,sequence) ['BAB', 'BEB', 'BIB'] But just curious; are we reinventing the wheel here? Is there already a way to match even overlapping substrings? I'm surprised I can't find one. AFAIK that is the way to do it. You can shorten it a little by using result.group() instead of seq[result.start():result.end()]. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor