[Tutor] ssh script
Hello, I'm trying to write a script which will allow me to create a reverse tunnel from a remote machine using SSH -R I know the reverse tunnel script works on it's own run from the shell, but I don't want to leave it open always... does anyone have any ideas on how to make this work? There seems to be something wrong with the subprocess call such that it just hangs on the remote side... #!/usr/bin/python import os, time, subprocess REMOTE_HOME='../' #mounted drive to REMOTE_HOME from LOCAL_MACHINE cmd = 'while true; do ssh -R 8022:localhost:22 [EMAIL PROTECTED] ; sleep 60; done' while 1: while os.path.exists(os.path.join(REMOTE_HOME,'mySecretFile'): proc=subprocess.call(cmd,shell='True') if proc: os.kill(proc.pid) if os.path.exists(os.path.join(REMOTE_HOME,'KillScript'): break -- View this message in context: http://www.nabble.com/ssh-script-tp15038129p15038129.html Sent from the Python - tutor mailing list archive at Nabble.com. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Projects
On Tue, Jan 22, 2008 at 11:10:18PM +, Damian Archer wrote: >So anyone have any good project ideas, perhaps projects that people >have >undertaken before?? I am in the same situation as you are. What I now did was doing something practical and some fun stuff: such as writing a statistic-tool for my mails, a script what automagically produces latex-letters and playing around with www.pythonchallenge.com -- Benjamin Eckenfels OpenPGP Key id: CF56E489 Key fingerprint = 386D CBE1 0833 4C12 2871 F51E 839D 18EF CF56 E489 Public Key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xCF56E489 signature.asc Description: Digital signature ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Projects
Damian Archer wrote: > So anyone have any good project ideas, perhaps projects that people have > undertaken before?? This just came up on the list: http://mail.python.org/pipermail/tutor/2008-January/059653.html Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Boost python
hi, I have hello.cpp and hello.py file. I want to access hello.cpp from hello.py. How can I do that. I tried to find the solutions, I got Boost python. I saw the tutorial I tried to do what they mentioned in the tutorial. I confused with "jamfile" and "project-root". I am using debian I tried only the "bjam" method. I installed bjam,boost-python. If any one familiar with this then help me. -- Thanks & Regards, goldgod ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] csv.reader: bad argument type
I don't get this. I wrote a script that reads data from a .csv file and puts them into a MySQL database. It works fine on my machine. Here's the relevant part: import csv import MySQLdb import sys try: datei = sys.argv[1] except: print("Usage: insert_into_db <.csv-file>") # convert csv to list reader = csv.reader(open(datei, "rb"), delimiter = ";", quotechar = "", quoting = csv.QUOTE_NONE) After copying it to the server, it says: server1:/usr/local/sbin# ./insert_dgf_customers.py /usr/local/sbin/my.csv Traceback (most recent call last): File "./insert_dgf_customers.py", line 27, in ? reader = csv.reader(open(datei, "rb"), delimiter = ";", quotechar = "", quoting = csv.QUOTE_NONE) TypeError: bad argument type for built-in operation The file my.csv is a test file and correctly formatted (it's the same file that worked on the other machine). I thought the built-in operation meant here is open(), but without putting csv.reader() around it everything works fine... And I guess csv.reader is _not_ built-in, for it from the module - is that correct? Any hints? -paul ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] csv.reader: bad argument type
[EMAIL PROTECTED] wrote: > import csv > import MySQLdb > import sys > > try: > datei = sys.argv[1] > except: > print("Usage: insert_into_db <.csv-file>") > > # convert csv to list > reader = csv.reader(open(datei, "rb"), delimiter = ";", quotechar = "", > quoting = csv.QUOTE_NONE) > > > After copying it to the server, it says: > > server1:/usr/local/sbin# ./insert_dgf_customers.py /usr/local/sbin/my.csv > Traceback (most recent call last): >File "./insert_dgf_customers.py", line 27, in ? > reader = csv.reader(open(datei, "rb"), delimiter = ";", quotechar = > "", quoting = csv.QUOTE_NONE) > TypeError: bad argument type for built-in operation > > > The file my.csv is a test file and correctly formatted (it's the same > file that worked on the other machine). It doesn't seem to get as far as actually reading the file. > I thought the built-in operation meant here is open(), but without > putting csv.reader() around it everything works fine... And I guess > csv.reader is _not_ built-in, for it from the module - is that correct? csv.reader is not built-in, that is correct. But it is implemented in C so you won't get a good traceback into where the failure is actually occurring. What version of Python is on the two machines? A couple of things to try, maybe some hints will come out: - print the value of datei just to make sure nothing funny there - split the open to a separate line to make sure it is the call to reader that is the problem: f = open(datei, "rb") reader = csv.reader(f, delimiter = ";", quotechar = "", quoting = csv.QUOTE_NONE) Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] csv.reader: bad argument type
Kent Johnson schrieb: > [EMAIL PROTECTED] wrote: > >> import csv >> import MySQLdb >> import sys >> >> try: >> datei = sys.argv[1] >> except: >> print("Usage: insert_into_db <.csv-file>") >> >> # convert csv to list >> reader = csv.reader(open(datei, "rb"), delimiter = ";", quotechar = >> "", quoting = csv.QUOTE_NONE) >> >> >> After copying it to the server, it says: >> >> server1:/usr/local/sbin# ./insert_dgf_customers.py /usr/local/sbin/my.csv >> Traceback (most recent call last): >>File "./insert_dgf_customers.py", line 27, in ? >> reader = csv.reader(open(datei, "rb"), delimiter = ";", quotechar >> = "", quoting = csv.QUOTE_NONE) >> TypeError: bad argument type for built-in operation >> >> >> The file my.csv is a test file and correctly formatted (it's the same >> file that worked on the other machine). > > It doesn't seem to get as far as actually reading the file. > >> I thought the built-in operation meant here is open(), but without >> putting csv.reader() around it everything works fine... And I guess >> csv.reader is _not_ built-in, for it from the module - is that correct? > > csv.reader is not built-in, that is correct. But it is implemented in C > so you won't get a good traceback into where the failure is actually > occurring. > > What version of Python is on the two machines? I guess that's it - my client has 2.5 while the server runs 2.4 ... I don't think any differences are mentioned in the library reference for csv but I'll have a second look. > A couple of things to try, maybe some hints will come out: > - print the value of datei just to make sure nothing funny there Filename is alright - my.csv > - split the open to a separate line to make sure it is the call to > reader that is the problem: > f = open(datei, "rb") > reader = csv.reader(f, delimiter = ";", quotechar = "", quoting = > csv.QUOTE_NONE) Same result. Thanks nonetheless :) > Kent > - Paul ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] csv.reader: bad argument type
[EMAIL PROTECTED] wrote: > I guess that's it - my client has 2.5 while the server runs 2.4 ... I > don't think any differences are mentioned in the library reference for > csv but I'll have a second look. According to http://www.python.org/doc/2.5/whatsnew/modules.html "The csv module, which parses files in comma-separated value format, received several enhancements and a number of bugfixes." FWIW the Python 2.5 change history for _csv.c is here: http://svn.python.org/view/python/trunk/Modules/_csv.c?rev=59564&view=log and for Python 2.4 here: http://svn.python.org/view/python/branches/release24-maint/Modules/_csv.c?rev=52247&view=log Nothing jumps out at me as the cause of your problem, though. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Projects
On Jan 22, 2008 5:10 PM, Damian Archer <[EMAIL PROTECTED]> wrote: > So anyone have any good project ideas, perhaps projects that people have > undertaken before?? > > I'm taking a Java class this semester and our first program is a number translator. Here's the assignment: *Below is a sample run:* Welcome to my number translator! Enter amount [0-99.99; 0 to exit]: 1234.56 Translation: one thousand two hundred thirty-four and 56/100 Enter amount [0-99.99; 0 to exit]: 17775 Translation: seventeen thousand seven hundred seventy-five and 00/100 Enter amount [0-99.99; 0 to exit]: -45 Enter amount [0-99.99; 0 to exit]: 9.99 Enter amount [0-99.99; 0 to exit]: 22.95 Translation: twenty-two and 95/100 Enter amount [0-99.99; 0 to exit]: 0.01 Translation: zero and 01/100 Enter amount [0-99.99; 0 to exit]: 909909.99 Translation: nine hundred nine thousand nine hundred nine and 99/100 Enter amount [0-99.99; 0 to exit]: 0 Bye bye! *Input* You may assume that your input is in floating point format (no dollar signs or commas or other special characters other than a single decimal point). But you will need to check to make sure your input satisfies the specs given above. (Although with exception handling it's not difficult to validate that you have floating point format.) --- An example routine to translate a number into it's english equivalent was given (again, this is Java): static String convertDigitToEnglish(int d) { switch ( d ) { case 1: return "one"; case 2: return "two"; case 3: return "three"; case 4: return "four"; case 5: return "five"; case 6: return "six"; case 7: return "seven"; case 8: return "eight"; case 9: return "nine"; default: return "\nFatal Error!\n"; // should I abort pgm? } // end of switch } // end of convertDigitToEnglish In Python I'd just use a dictionary. HTH, jason ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] ssh script
Have you looked into Paramiko? http://www.lag.net/paramiko/ Its a port of the ssh2 protocol for python. It might be easier to do this using that that subprocess calls. Paramiko is quite nice, I use it a lot at work. Just a suggestion J On Jan 23, 2008 3:42 AM, washakie <[EMAIL PROTECTED]> wrote: > > Hello, I'm trying to write a script which will allow me to create a > reverse > tunnel from a remote machine using SSH -R > > I know the reverse tunnel script works on it's own run from the shell, but > I > don't want to leave it open always... does anyone have any ideas on how to > make this work? There seems to be something wrong with the subprocess call > such that it just hangs on the remote side... > > #!/usr/bin/python > > import os, time, subprocess > REMOTE_HOME='../' #mounted drive to REMOTE_HOME from LOCAL_MACHINE > > cmd = 'while true; do ssh -R 8022:localhost:22 [EMAIL PROTECTED] ; > sleep > 60; done' > while 1: >while os.path.exists(os.path.join(REMOTE_HOME,'mySecretFile'): >proc=subprocess.call(cmd,shell='True') > >if proc: os.kill(proc.pid) > >if os.path.exists(os.path.join(REMOTE_HOME,'KillScript'): >break > > -- > View this message in context: > http://www.nabble.com/ssh-script-tp15038129p15038129.html > Sent from the Python - tutor mailing list archive at Nabble.com. > > ___ > 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] MySQLdb for Python 2.5? (Debian related) (was: csv.reader: bad argument type)
I decided to install Python2.5 on the server machine to save me the time for low-level debugging >;) but it doesn't find the MySQLdb module... I searched through aptitude - the only thing I find is MySQLdb for Py2.4 ... What's happening here? I have to say that the client PC (on which my script runs fine with 2.5) has Ubuntu installed - can it be that the MySQLdb module is behind in Debian? Sorry for going off topic - if you guys don't want that here can move the problem to the Debian list - but maybe someone here knows about the status of the packages...? - Paul ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] MySQLdb for Python 2.5? (Debian related) (was: csv.reader: bad argument type)
I run MySQLdb with Python 2.5.1, but I had to build it manually. It was not part of any prebuilt package on my RedHat box. You should be able to do the same. J On Jan 23, 2008 10:01 AM, <[EMAIL PROTECTED]> wrote: > I decided to install Python2.5 on the server machine to save me the time > for low-level debugging >;) but it doesn't find the MySQLdb module... > > I searched through aptitude - the only thing I find is MySQLdb for Py2.4 > ... What's happening here? > > I have to say that the client PC (on which my script runs fine with 2.5) > has Ubuntu installed - can it be that the MySQLdb module is behind in > Debian? > > Sorry for going off topic - if you guys don't want that here can move > the problem to the Debian list - but maybe someone here knows about the > status of the packages...? > > - Paul > ___ > 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] ssh script
washakie wrote: > Hello, I'm trying to write a script which will allow me to create a reverse > tunnel from a remote machine using SSH -R > > I know the reverse tunnel script works on it's own run from the shell, but I > don't want to leave it open always... does anyone have any ideas on how to > make this work? There seems to be something wrong with the subprocess call > such that it just hangs on the remote side... > > #!/usr/bin/python > > import os, time, subprocess > REMOTE_HOME='../' #mounted drive to REMOTE_HOME from LOCAL_MACHINE > > cmd = 'while true; do ssh -R 8022:localhost:22 [EMAIL PROTECTED] ; sleep > You probably need to add "-t" to the ssh invocation since you won't have a controlling terminal. If that doesn't fix it, then try inserting some debugging output to know what's going on. > 60; done' > while 1: > while os.path.exists(os.path.join(REMOTE_HOME,'mySecretFile'): > proc=subprocess.call(cmd,shell='True') > > if proc: os.kill(proc.pid) > > if os.path.exists(os.path.join(REMOTE_HOME,'KillScript'): > break > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] MySQLdb for Python 2.5? (Debian related) (was: csv.reader: bad argument type)
It's a distribution issue. As far as what I've found as having cutting edge (or even reasonably fresh) python packages in your package manager is dictated by the distro, who vary wildly in this. Debian SID at times> All the Ubuntus > Debian SID at times> Fedora Core > Debian testing > Debian stable This is the #1 reason I use ubuntu on servers right now. And if the above is wrong now, these are generally feelings about a small sample set over a period of time. I really have just gone all Kubuntu/Xubuntu where I can these days. I will suggest you look into learning eggs, cheese shop and easy_install as an alternative to OS based package management for python. I was an awesome presentation by Brandon Rhodes Mill about Buildout at PyAtl a couple weeks ago. It automagically downloads all the eggs you need. You just create a setup.py and a quick config file, and check those in with your source. When you run a command when you start developing on a checkout, it pulls down all the eggs you need to work with that checkout from the cheeshop, putting them in a project local directory, which is then prepended to the python search path for that project. This means site-packages and you don't have fights when you install on multiple system who may need other past versions of modules. Buildout also gets the right version of python on the machine ( in a local directory again ) and is compatible with system where you don't have root access. Buildout was originally written by the Zope people I believe, but has been made independent of zope so all of us non-zope people can use it. --Michael Cheese Shop: www.python.org/pypi Monty Python Cheese Shop Skit: www.youtube.com/watch?v=B3KBuQHHKx0 Buildout: www.python.org/pypi/zc.buildout More about Eggs: http://peak.telecommunity.com/DevCenter/PythonEggs PyAtl (where presumably his talk will be posted): http://pyatl.org/ On Jan 23, 2008 11:01 AM, <[EMAIL PROTECTED]> wrote: > I decided to install Python2.5 on the server machine to save me the time > for low-level debugging >;) but it doesn't find the MySQLdb module... > > I searched through aptitude - the only thing I find is MySQLdb for Py2.4 > ... What's happening here? > > I have to say that the client PC (on which my script runs fine with 2.5) > has Ubuntu installed - can it be that the MySQLdb module is behind in > Debian? > > Sorry for going off topic - if you guys don't want that here can move > the problem to the Debian list - but maybe someone here knows about the > status of the packages...? > > - Paul > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- Michael Langford Phone: 404-386-0495 Consulting: http://www.RowdyLabs.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] MySQLdb for Python 2.5? (Debian related) (was: csv.reader: bad argument type)
It's a distribution issue. As far as what I've found as having cutting edge (or even reasonably fresh) python packages in your package manager is dictated by the distro, who vary wildly in this. Debian SID at times> All the Ubuntus > Debian SID at times> Fedora Core > Debian testing > Debian stable This is the #1 reason I use ubuntu on servers right now. And if the above is wrong now, these are generally feelings about a small sample set over a period of time. I really have just gone all Kubuntu/Xubuntu where I can these days. I will suggest you look into learning eggs, cheese shop and easy_install as an alternative to OS based package management for python. I was an awesome presentation by Brandon Rhodes Mill about Buildout at PyAtl a couple weeks ago. It automagically downloads all the eggs you need. You just create a setup.py and a quick config file, and check those in with your source. When you run a command when you start developing on a checkout, it pulls down all the eggs you need to work with that checkout from the cheeshop, putting them in a project local directory, which is then prepended to the python search path for that project. This means site-packages and you don't have fights when you install on multiple system who may need other past versions of modules. Buildout also gets the right version of python on the machine ( in a local directory again ) and is compatible with system where you don't have root access. Buildout was originally written by the Zope people I believe, but has been made independent of zope so all of us non-zope people can use it. --Michael Cheese Shop: www.python.org/pypi Monty Python Cheese Shop Skit: www.youtube.com/watch?v=B3KBuQHHKx0 Buildout: www.python.org/pypi/zc.buildout More about Eggs: http://peak.telecommunity.com/DevCenter/PythonEggs PyAtl (where presumably his talk will be posted): http://pyatl.org/ - Show quoted text - On Jan 23, 2008 11:01 AM, <[EMAIL PROTECTED]> wrote: > I decided to install Python2.5 on the server machine to save me the time > for low-level debugging >;) but it doesn't find the MySQLdb module... > > I searched through aptitude - the only thing I find is MySQLdb for Py2.4 > ... What's happening here? > > I have to say that the client PC (on which my script runs fine with 2.5) > has Ubuntu installed - can it be that the MySQLdb module is behind in > Debian? > > Sorry for going off topic - if you guys don't want that here can move > the problem to the Debian list - but maybe someone here knows about the > status of the packages...? > > - Paul > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- Michael Langford Phone: 404-386-0495 Consulting: http://www.RowdyLabs.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] ssh script
I've done similar with pexpect: http://pexpect.sourceforge.net/ washakie wrote: > Hello, I'm trying to write a script which will allow me to create a reverse > tunnel from a remote machine using SSH -R > > I know the reverse tunnel script works on it's own run from the shell, but I > don't want to leave it open always... does anyone have any ideas on how to > make this work? There seems to be something wrong with the subprocess call > such that it just hangs on the remote side... > > #!/usr/bin/python > > import os, time, subprocess > REMOTE_HOME='../' #mounted drive to REMOTE_HOME from LOCAL_MACHINE > > cmd = 'while true; do ssh -R 8022:localhost:22 [EMAIL PROTECTED] ; sleep > 60; done' > while 1: > while os.path.exists(os.path.join(REMOTE_HOME,'mySecretFile'): > proc=subprocess.call(cmd,shell='True') > > if proc: os.kill(proc.pid) > > if os.path.exists(os.path.join(REMOTE_HOME,'KillScript'): > break ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Projects
On Wed, 23 Jan 2008, Jason Massey wrote: > An example routine to translate a number into [its] english equivalent > was given (again, this is Java): > static String convertDigitToEnglish(int d) { > switch ( d ) > { > > case 1: return "one"; > case 2: return "two"; > case 3: return "three"; > case 4: return "four"; > case 5: return "five"; > case 6: return "six"; > case 7: return "seven"; > case 8: return "eight"; > case 9: return "nine"; > default: return "\nFatal Error!\n"; // should I abort pgm? > } // end of switch > } // end of convertDigitToEnglish > > In Python I'd just use a dictionary. I'm no Java expert, but isn't Java's Map more or less equivalent to Python's dictionary? http://java.sun.com/javase/6/docs/api/java/util/Map.html ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Projects
Terry Carroll wrote: > I'm no Java expert, but isn't Java's Map more or less equivalent to > Python's dictionary? More or less, except Python dicts are about 10x easier to use. Some (overly complicated) examples here: http://personalpages.tds.net/~kent37/stories/00017.html Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] MySQLdb for Python 2.5? (Debian related)
Sounds very good! I think I read something about Python eggs some time ago, but didn't look deeper into it then. I'll do so tomorrow (if I find some spare time - there's so much to do...) However, Debian is known for stability and security, right? I don't know if I should install things without apt in a production environment, so I first have to ask my guru if it's alright. Maybe that sounds paranoid, but I'm new to Linux and all these server programs that make my head fuzzy o.O Thanks for pointing to cheese shop etc.! Michael Langford schrieb: > It's a distribution issue. As far as what I've found as having cutting > edge (or even reasonably fresh) python packages in your package > manager is dictated by the distro, who vary wildly in this. > > Debian SID at times> All the Ubuntus > Debian SID at times> Fedora > Core > Debian testing > Debian stable > > This is the #1 reason I use ubuntu on servers right now. And if the > above is wrong now, these are generally feelings about a small sample > set over a period of time. I really have just gone all Kubuntu/Xubuntu > where I can these days. > > I will suggest you look into learning eggs, cheese shop and > easy_install as an alternative to OS based package management for > python. I was an awesome presentation by Brandon Rhodes Mill about > Buildout at PyAtl a couple weeks ago. It automagically downloads all > the eggs you need. You just create a setup.py and a quick config file, > and check those in with your source. When you run a command when you > start developing on a checkout, it pulls down all the eggs you need to > work with that checkout from the cheeshop, putting them in a project > local directory, which is then prepended to the python search path for > that project. > > This means site-packages and you don't have fights when you install on > multiple system who may need other past versions of modules. Buildout > also gets the right version of python on the machine ( in a local > directory again ) and is compatible with system where you don't have > root access. > > Buildout was originally written by the Zope people I believe, but has > been made independent of zope so all of us non-zope people can use it. > > --Michael > > Cheese Shop: www.python.org/pypi > Monty Python Cheese Shop Skit: www.youtube.com/watch?v=B3KBuQHHKx0 > Buildout: www.python.org/pypi/zc.buildout > More about Eggs: http://peak.telecommunity.com/DevCenter/PythonEggs > PyAtl (where presumably his talk will be posted): http://pyatl.org/ > > On Jan 23, 2008 11:01 AM, <[EMAIL PROTECTED]> wrote: >> I decided to install Python2.5 on the server machine to save me the time >> for low-level debugging >;) but it doesn't find the MySQLdb module... >> >> I searched through aptitude - the only thing I find is MySQLdb for Py2.4 >> ... What's happening here? >> >> I have to say that the client PC (on which my script runs fine with 2.5) >> has Ubuntu installed - can it be that the MySQLdb module is behind in >> Debian? >> >> Sorry for going off topic - if you guys don't want that here can move >> the problem to the Debian list - but maybe someone here knows about the >> status of the packages...? >> >> - Paul >> ___ >> 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] MySQLdb for Python 2.5? (Debian related)
> However, Debian is known for stability and security, right? I don't know > if I should install things without apt in a production environment, so I > first have to ask my guru if it's alright. The *point* of buildout is that the entire installation is *local* to the application. There is no change system wide, just for the application that is running. This is *much* safer than using the system package manager. Its like running a standalone exe like putty on windows, versus installing a microsoft product. --Michael > Michael Langford schrieb: > > It's a distribution issue. As far as what I've found as having cutting > > edge (or even reasonably fresh) python packages in your package > > manager is dictated by the distro, who vary wildly in this. > > > > Debian SID at times> All the Ubuntus > Debian SID at times> Fedora > > Core > Debian testing > Debian stable > > > > This is the #1 reason I use ubuntu on servers right now. And if the > > above is wrong now, these are generally feelings about a small sample > > set over a period of time. I really have just gone all Kubuntu/Xubuntu > > where I can these days. > > > > I will suggest you look into learning eggs, cheese shop and > > easy_install as an alternative to OS based package management for > > python. I was an awesome presentation by Brandon Rhodes Mill about > > Buildout at PyAtl a couple weeks ago. It automagically downloads all > > the eggs you need. You just create a setup.py and a quick config file, > > and check those in with your source. When you run a command when you > > start developing on a checkout, it pulls down all the eggs you need to > > work with that checkout from the cheeshop, putting them in a project > > local directory, which is then prepended to the python search path for > > that project. > > > > This means site-packages and you don't have fights when you install on > > multiple system who may need other past versions of modules. Buildout > > also gets the right version of python on the machine ( in a local > > directory again ) and is compatible with system where you don't have > > root access. > > > > Buildout was originally written by the Zope people I believe, but has > > been made independent of zope so all of us non-zope people can use it. > > > > --Michael > > > > Cheese Shop: www.python.org/pypi > > Monty Python Cheese Shop Skit: www.youtube.com/watch?v=B3KBuQHHKx0 > > Buildout: www.python.org/pypi/zc.buildout > > More about Eggs: http://peak.telecommunity.com/DevCenter/PythonEggs > > PyAtl (where presumably his talk will be posted): http://pyatl.org/ > > > > On Jan 23, 2008 11:01 AM, <[EMAIL PROTECTED]> wrote: > >> I decided to install Python2.5 on the server machine to save me the time > >> for low-level debugging >;) but it doesn't find the MySQLdb module... > >> > >> I searched through aptitude - the only thing I find is MySQLdb for Py2.4 > >> ... What's happening here? > >> > >> I have to say that the client PC (on which my script runs fine with 2.5) > >> has Ubuntu installed - can it be that the MySQLdb module is behind in > >> Debian? > >> > >> Sorry for going off topic - if you guys don't want that here can move > >> the problem to the Debian list - but maybe someone here knows about the > >> status of the packages...? > >> > >> - Paul > >> ___ > >> Tutor maillist - Tutor@python.org > >> http://mail.python.org/mailman/listinfo/tutor > >> > > > > > > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- Michael Langford Phone: 404-386-0495 Consulting: http://www.RowdyLabs.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Projects (fwd)
Hi Jason, Looking back at that Java code: static String convertDigitToEnglish(int d) { switch ( d ) { case 1: return "one"; case 2: return "two"; case 3: return "three"; case 4: return "four"; case 5: return "five"; case 6: return "six"; case 7: return "seven"; case 8: return "eight"; case 9: return "nine"; default: return "\nFatal Error!\n"; // should I abort pgm? } // end of switch } // end of convertDigitToEnglis Frankly, this seems silly to me. First, it ignores zero, which is a cardinal sin. I'm being somewhat serious about this: functions should do what they say, and that function isn't. But the code could also be written much more tightly as: static String digitToString(int n) { String[] words = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; if (0 <= n && n < 10) { return words[n]; } throw new IllegalArgumentException("input not a single digit"); } I don't mean to make this post so Java-centric; it just seems a little unfair to compare a bad Java routine to a good Python routine. :) Writing an equivalent in Python is also pretty straightforward: # ## Pseudocode: just a sketch def digitToString(n): words = ["zero", "one", ...] if 0 <= n < 10: return words[n] ... # Like dictionaries, the list data structure works pretty well for key/value lookup if the input key is a small number. Good luck! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Projects (fwd)
Danny Yoo wrote: > Hi Jason, > > > Looking back at that Java code: > > > static String convertDigitToEnglish(int d) { > switch ( d ) > { >case 1: return "one"; >case 2: return "two"; >case 3: return "three"; >case 4: return "four"; >case 5: return "five"; >case 6: return "six"; >case 7: return "seven"; >case 8: return "eight"; >case 9: return "nine"; >default: return "\nFatal Error!\n"; // should I abort pgm? > } // end of switch >} // end of convertDigitToEnglis > > > > Frankly, this seems silly to me. First, it ignores zero, which is a cardinal > sin. I'm being somewhat serious about this: functions should do what they > say, > and that function isn't. > > > But the code could also be written much more tightly as: > > > static String digitToString(int n) { >String[] words = {"zero", "one", "two", "three", "four", > "five", "six", "seven", "eight", "nine"}; >if (0 <= n && n < 10) { >return words[n]; >} >throw new IllegalArgumentException("input not a single digit"); > } > > > I don't mean to make this post so Java-centric; it just seems a little unfair > to compare a bad Java routine to a good Python routine. :) Writing an > equivalent in Python is also pretty straightforward: > > # > ## Pseudocode: just a sketch > def digitToString(n): > words = ["zero", "one", ...] > if 0 <= n < 10: > return words[n] > ... > # > > Like dictionaries, the list data structure works pretty well for key/value > lookup if the input key is a small number. > > > Good luck! > up to a thousand (not tested) words = {0:'zero', 1:'one', 2:'two', 3:'three', ... , 10:'ten', 11:'eleven', 12:'twelve', ..., 19:'nineteen', 20:'twenty', , 90:'ninety', 100:'one hundred' } def digitToString(n) : try : retStr = words[n] except KeyError : if n > 100 : retStr = (digitToString(n // 100) + ' hundred and ' + digitToString(n % 100)) else : retStr = (digitToString(n - (n % 10)) + ' ' + digitToString(n % 10)) return retStr HTH ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Projects (fwd)
> up to a thousand (not tested) > > words = {0:'zero', 1:'one', 2:'two', 3:'three', ... , 10:'ten', > 11:'eleven', 12:'twelve', ..., 19:'nineteen', > 20:'twenty', , 90:'ninety', 100:'one hundred' } > def digitToString(n) : >try : >retStr = words[n] >except KeyError : >if n > 100 : >retStr = (digitToString(n // 100) > + ' hundred and ' > + digitToString(n % 100)) >else : >retStr = (digitToString(n - (n % 10)) > + ' ' > + digitToString(n % 10)) > >return retStr This could be written much more efficiently. It can be done with only these lists~ ones = ['zero','one','two','three','four','five','six','seven','eight','nine'] teens = ['ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen'] tens = ['','','twenty','thirty','fourty','fifty','sixty','seventy','eighty','ninety'] hundstr = 'hundred' thousand = 'thousand' Exercise for reader to make it work ;-) Unless of course you genuinely want to see my code... Current range 0 - 999,999Easily extendable to millions, trillions, billions, etc. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Projects (fwd)
Tiger12506 wrote: >> up to a thousand (not tested) >> >> words = {0:'zero', 1:'one', 2:'two', 3:'three', ... , 10:'ten', >> 11:'eleven', 12:'twelve', ..., 19:'nineteen', >> 20:'twenty', , 90:'ninety', 100:'one hundred' } >> def digitToString(n) : >>try : >>retStr = words[n] >>except KeyError : >>if n > 100 : >>retStr = (digitToString(n // 100) >> + ' hundred and ' >> + digitToString(n % 100)) >>else : >>retStr = (digitToString(n - (n % 10)) >> + ' ' >> + digitToString(n % 10)) >> >>return retStr > > This could be written much more efficiently. It can be done with only these > lists~ > ones = > ['zero','one','two','three','four','five','six','seven','eight','nine'] > teens = > ['ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen'] > tens = > ['','','twenty','thirty','fourty','fifty','sixty','seventy','eighty','ninety'] > hundstr = 'hundred' > thousand = 'thousand' > Isn't dictionary access faster than list access? Why are three lists 'much more efficient'? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Projects (fwd)
> This could be written much more efficiently. It can be done with only > these > lists~ > ones = > ['zero','one','two','three','four','five','six','seven','eight','nine'] > teens = > ['ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen'] What is it with me and mistakes lately? These two lists above should be combined into one. Saves a couple of range checks in the program. :-{ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Projects (fwd)
> Isn't dictionary access faster than list access? Why are three lists > 'much more efficient'? Oh no, no, no. Dictionaries are faster when you are *searching through* for a particular value. If you already know the index of the item in the list, lists are much faster. Dictionaries are hash based. Somewhere it has to calculate the hash of the key you give it... These three lists are more efficient in terms of size/output ratio. It appeared as if the dictionary that was presented as an example was just going to map one to one all of the values from zero to 999,999 (to match my list version capabilities). Not only is that bad programming style, it's just plain unecessary. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Projects (fwd)
On 24/01/2008, Ricardo Aráoz <[EMAIL PROTECTED]> wrote: > Isn't dictionary access faster than list access? Why are three lists > 'much more efficient'? Well, not necessarily. If you want a dictionary, you could use a list of tuples: myDict = [('a', 'one'), ('b', 'two), ('c', 'three')] Then you could do lookup as: def lookup(key, listDict): for k, v in listDict: if k == key: return v But, as you say, this would be a lot slower than using a dict (lookup time is proportional to the length of the list for this naive dictionary, whereas lookup time is essentially constant with a dict). However, in this case, the keys are integers starting from 0 with no holes. Instead of having to search, our lookup is just: return digits[i] which is also constant time. If you really want to know which is faster, the timeit module is your friend. Here's what my computer says: Morpork:~ repton$ python -m timeit -s 'd = {0:"zero", 1:"one", 2:"two", 3:"three", 4:"four", 5:"five", 6:"six", 7:"seven", 8:"eight", 9:"nine"}' 'd[5]' 1000 loops, best of 3: 0.127 usec per loop Morpork:~ repton$ python -m timeit -s 'd = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]' 'd[5]' 1000 loops, best of 3: 0.102 usec per loop So, if that extra 25 nanoseconds is important to you, definitely go with the list! -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Projects (fwd)
Danny Yoo wrote: > [snip] > First, it ignores zero, which is a cardinal sin. Or is it an ordinal sin? [snip] ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] TypeError in base class __init__ after reload
Hello Pythonistas, Running the script 'instantiate_and_reload.py' gives me the error TypeError: unbound method __init__() must be called with ParentClass instance as first argument (got ChildClass instance instead) on the last call to ChildClass(), at line 23. The earlier calls don't trigger the error. -- Begin file instantiate_and_reload.py: from parentclass import ParentClass from childclass import ChildClass import parentclass, childclass p = parentclass.ParentClass() c = childclass.ChildClass() p = ParentClass() c = ChildClass() reload(parentclass) p = parentclass.ParentClass() c = childclass.ChildClass() p = ParentClass() c = ChildClass() reload(childclass) p = parentclass.ParentClass() c = childclass.ChildClass() p = ParentClass() c = ChildClass() -- End of file instantiate_and_reload.py -- Begin file parentclass.py: class ParentClass(): #same result with new-style classes (subclassing object) def __init__(self): pass if __name__ == '__main__': p = ParentClass() -- End of file parentclass.py -- Begin file childclass.py: from parentclass import ParentClass import parentclass class ChildClass(ParentClass): def __init__(self): ParentClass.__init__(self) if __name__ == '__main__': p = ParentClass() c = ChildClass() reload(parentclass) p = ParentClass() c = ChildClass() -- End of file childclass.py -- Beginning of captured command-line session: D:\Programs\Python\Sandbox\SubclassInitChain>python childclass.py D:\Programs\Python\Sandbox\SubclassInitChain>python parentclass.py D:\Programs\Python\Sandbox\SubclassInitChain>python instantiate_and_reload.py Traceback (most recent call last): File "instantiate_and_reload.py", line 23, in c = ChildClass() File "D:\Programs\Python\Sandbox\SubclassInitChain\childclass.py", line 7, in __init__ ParentClass.__init__(self) TypeError: unbound method __init__() must be called with ParentClass instance as first argument (got ChildClass instance instead) D:\Programs\Python\Sandbox\SubclassInitChain>python -V Python 2.5.1 -- end of captured command-line session I can't understand why the last call to ChildClass() triggers the error, when the earlier calls don't. Can somebody explain to me what's going on? or what I'm doing wrong? Thanks - Dan Knierim ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor