Executing remote command with paramiko
Hey, I'm trying to run a sudo guarded command over SSH using paramiko +++ s = paramiko.SSHClient() s.load_system_host_keys() s.connect(hostname, port, username, passwd) stdin, stdout, stderr = s.exec_command('sudo -s') stdin.write('password\n') stdin.flush() print 'Flushing' stdin, stdout, stderr = s.exec_command('harvester') print stdout.read() s.close() +++ It seems to me that the sudo -s isn't getting executed at all. I commented the sudo -s code lines and no error is shown. Thanks for help and time. -- http://mail.python.org/mailman/listinfo/python-list
A little help with pexpect
Hey, I'm trying to execute a command over a remore server using pexpect + url = 'ssh internalserver' res = pexpect.spawn(url) print '1' res.expect('.*ssword:') print '2' res.sendline('mypasswd') print '3' res.sendline('ls -aslh') + What I want to do is to send a couple of commands and get the response. How to do this? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Remoting over SSH
Hey, I want to perform commands on a remote server over SSH. What do I need? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Characters aren't displayed correctly
On Mar 2, 5:40 pm, John Machin sjmac...@lexicon.net wrote: On Mar 3, 1:50 am, Hussein B hubaghd...@gmail.com wrote: On Mar 2, 4:31 pm, John Machin sjmac...@lexicon.net wrote: On Mar 2, 7:30 pm, Hussein B hubaghd...@gmail.com wrote: On Mar 1, 4:51 pm, Philip Semanchuk phi...@semanchuk.com wrote: On Mar 1, 2009, at 8:31 AM, Hussein B wrote: Hey, I'm retrieving records from MySQL database that contains non english characters. Can you reveal which language??? Arabic Then I create a String that contains HTML markup and column values from the previous result set. + markup = u'''table.''' for row in rows: markup = markup + 'trtd' + row['id'] markup = markup + '/table + Then I'm sending the email according to this tip: http://code.activestate.com/recipes/473810/ Well, the email contains ? characters for each non english ones. Any ideas? There's so many places where this could go wrong and you haven't narrowed down the problem. Are the characters stored in the database correctly? Yes they are. How do you KNOW that they are stored correctly? What makes you so sure? Because MySQL Query Browser displays them correctly, in addition I use BIRT as the reporting system and it shows them correctly. Are they stored consistently (i.e. all using the same encoding, not some using utf-8 and others using iso-8859-1)? Yes. So what is the encoding used to store them? Tables are created with UTF-8 encoding option What are you getting out of the database? Is it being converted to Unicode correctly, or at all? I don't know, how to make sure of this point? You could show us some of the output from the database query. As well as print the_output you should print repr(the_output) and show us both, and also tell us what you *expect* to see. The result of print repr(row['name']) is '??? ??' The '?' characters are supposed to be Arabic characters. Are you expecting 3 Arabic characters, a space, and then 6 Arabic characters? We now have some interesting evidence: row['name'] is NOT a unicode object -- otherwise the print would show u'??? ??'; it's a str object. So: A utf8-encoded string is being decoded to unicode, and then re- encoded to some other encoding, using the replace (with ?) error- handling method. That shouldn't be hard to spot! It's about time you showed us the code you are using to extract the data from the database, including the print statements you have put in. This is how I retrieve the data: db = MySQLdb.connect(host = 127.0.0.1, port = 3306, user = username, passwd = passwd, db = reporting) cr = db.cursor(MySQLdb.cursors.DictCursor) cr.execute(sql) rows = cr.fetchall() Thanks all for your nice help. -- http://mail.python.org/mailman/listinfo/python-list
Re: Characters aren't displayed correctly
On Mar 3, 11:05 am, Hussein B hubaghd...@gmail.com wrote: On Mar 2, 5:40 pm, John Machin sjmac...@lexicon.net wrote: On Mar 3, 1:50 am, Hussein B hubaghd...@gmail.com wrote: On Mar 2, 4:31 pm, John Machin sjmac...@lexicon.net wrote: On Mar 2, 7:30 pm, Hussein B hubaghd...@gmail.com wrote: On Mar 1, 4:51 pm, Philip Semanchuk phi...@semanchuk.com wrote: On Mar 1, 2009, at 8:31 AM, Hussein B wrote: Hey, I'm retrieving records from MySQL database that contains non english characters. Can you reveal which language??? Arabic Then I create a String that contains HTML markup and column values from the previous result set. + markup = u'''table.''' for row in rows: markup = markup + 'trtd' + row['id'] markup = markup + '/table + Then I'm sending the email according to this tip: http://code.activestate.com/recipes/473810/ Well, the email contains ? characters for each non english ones. Any ideas? There's so many places where this could go wrong and you haven't narrowed down the problem. Are the characters stored in the database correctly? Yes they are. How do you KNOW that they are stored correctly? What makes you so sure? Because MySQL Query Browser displays them correctly, in addition I use BIRT as the reporting system and it shows them correctly. Are they stored consistently (i.e. all using the same encoding, not some using utf-8 and others using iso-8859-1)? Yes. So what is the encoding used to store them? Tables are created with UTF-8 encoding option What are you getting out of the database? Is it being converted to Unicode correctly, or at all? I don't know, how to make sure of this point? You could show us some of the output from the database query. As well as print the_output you should print repr(the_output) and show us both, and also tell us what you *expect* to see. The result of print repr(row['name']) is '??? ??' The '?' characters are supposed to be Arabic characters. Are you expecting 3 Arabic characters, a space, and then 6 Arabic characters? We now have some interesting evidence: row['name'] is NOT a unicode object -- otherwise the print would show u'??? ??'; it's a str object. So: A utf8-encoded string is being decoded to unicode, and then re- encoded to some other encoding, using the replace (with ?) error- handling method. That shouldn't be hard to spot! It's about time you showed us the code you are using to extract the data from the database, including the print statements you have put in. This is how I retrieve the data: db = MySQLdb.connect(host = 127.0.0.1, port = 3306, user = username, passwd = passwd, db = reporting) cr = db.cursor(MySQLdb.cursors.DictCursor) cr.execute(sql) rows = cr.fetchall() Thanks all for your nice help. Hey, I added use_unicode and charset keyword params to the connect() method and I got the following: u'\u062f\u062e\u0648\u0644 \u0633\u0631\u064a\u0639 \u0634\u0647\u0631' So characters are getting converted successfully. Well, using the previous recipe for sending the mail: http://code.activestate.com/recipes/473810/ I got the following error: Traceback (most recent call last): File HtmlMail.py, line 52, in module s.sendmail(sender, receiver , msg.as_string()) File /usr/lib/python2.5/email/message.py, line 131, in as_string g.flatten(self, unixfrom=unixfrom) File /usr/lib/python2.5/email/generator.py, line 84, in flatten self._write(msg) File /usr/lib/python2.5/email/generator.py, line 109, in _write self._dispatch(msg) File /usr/lib/python2.5/email/generator.py, line 135, in _dispatch meth(msg) File /usr/lib/python2.5/email/generator.py, line 201, in _handle_multipart g.flatten(part, unixfrom=False) File /usr/lib/python2.5/email/generator.py, line 84, in flatten self._write(msg) File /usr/lib/python2.5/email/generator.py, line 109, in _write self._dispatch(msg) File /usr/lib/python2.5/email/generator.py, line 135, in _dispatch meth(msg) File /usr/lib/python2.5/email/generator.py, line 201, in _handle_multipart g.flatten(part, unixfrom=False) File /usr/lib/python2.5/email/generator.py, line 84, in flatten self._write(msg) File /usr/lib/python2.5/email/generator.py, line 109, in _write self._dispatch(msg) File /usr/lib/python2.5/email/generator.py, line 135, in _dispatch meth(msg) File /usr/lib/python2.5/email/generator.py, line 178, in _handle_text self._fp.write(payload) UnicodeEncodeError: 'ascii' codec can't encode characters in position 115-118: ordinal not in range(128) Again, any ideas guys? :) Thanks to you all, you rocks ! -- http://mail.python.org/mailman/listinfo/python-list
Re: Characters aren't displayed correctly
On Mar 3, 12:21 pm, John Machin sjmac...@lexicon.net wrote: On Mar 3, 8:49 pm, Hussein B hubaghd...@gmail.com wrote: On Mar 3, 11:05 am, Hussein B hubaghd...@gmail.com wrote: On Mar 2, 5:40 pm, John Machin sjmac...@lexicon.net wrote: On Mar 3, 1:50 am, Hussein B hubaghd...@gmail.com wrote: On Mar 2, 4:31 pm, John Machin sjmac...@lexicon.net wrote: On Mar 2, 7:30 pm, Hussein B hubaghd...@gmail.com wrote: On Mar 1, 4:51 pm, Philip Semanchuk phi...@semanchuk.com wrote: On Mar 1, 2009, at 8:31 AM, Hussein B wrote: Hey, I'm retrieving records from MySQL database that contains non english characters. Can you reveal which language??? Arabic Then I create a String that contains HTML markup and column values from the previous result set. + markup = u'''table.''' for row in rows: markup = markup + 'trtd' + row['id'] markup = markup + '/table + Then I'm sending the email according to this tip: http://code.activestate.com/recipes/473810/ Well, the email contains ? characters for each non english ones. Any ideas? There's so many places where this could go wrong and you haven't narrowed down the problem. Are the characters stored in the database correctly? Yes they are. How do you KNOW that they are stored correctly? What makes you so sure? Because MySQL Query Browser displays them correctly, in addition I use BIRT as the reporting system and it shows them correctly. Are they stored consistently (i.e. all using the same encoding, not some using utf-8 and others using iso-8859-1)? Yes. So what is the encoding used to store them? Tables are created with UTF-8 encoding option What are you getting out of the database? Is it being converted to Unicode correctly, or at all? I don't know, how to make sure of this point? You could show us some of the output from the database query. As well as print the_output you should print repr(the_output) and show us both, and also tell us what you *expect* to see. The result of print repr(row['name']) is '??? ??' The '?' characters are supposed to be Arabic characters. Are you expecting 3 Arabic characters, a space, and then 6 Arabic characters? We now have some interesting evidence: row['name'] is NOT a unicode object -- otherwise the print would show u'??? ??'; it's a str object. So: A utf8-encoded string is being decoded to unicode, and then re- encoded to some other encoding, using the replace (with ?) error- handling method. That shouldn't be hard to spot! It's about time you showed us the code you are using to extract the data from the database, including the print statements you have put in. This is how I retrieve the data: db = MySQLdb.connect(host = 127.0.0.1, port = 3306, user = username, passwd = passwd, db = reporting) cr = db.cursor(MySQLdb.cursors.DictCursor) cr.execute(sql) rows = cr.fetchall() Thanks all for your nice help. Hey, I added use_unicode and charset keyword params to the connect() method Hey, that was a brilliant idea -- I was just about to ask you to try use_unicode=True, charset=utf8 ... what were the actual values that you used? I didn't supply values for them the first times. Let's suppose that you used charset= ... as far as I can tell, not being a mysqldb user myself, this means that your data tables and/ or your default connection don't use as an encoding. If so, this might be an issue you might like to take up with whoever created the database that you are using. and I got the following: u'\u062f\u062e\u0648\u0644 \u0633\u0631\u064a\u0639 \u0634\u0647\u0631' So characters are getting converted successfully. I guess so -- U+06nn sure are Arabic characters :-) However as suggested above, converted from what? might be worth pursuing if you like to understand what is going on instead of just applying magic recipes ;-) Well, using the previous recipe for sending the mail:http://code.activestate.com/recipes/473810/ I got the following error: Traceback (most recent call last): File HtmlMail.py, line 52, in module s.sendmail(sender, receiver , msg.as_string()) [big snip] _handle_text self._fp.write(payload) UnicodeEncodeError: 'ascii' codec can't encode characters in position 115-118: ordinal not in range(128) Again, any ideas guys? :) That recipe appears to have been written by an ascii bigot for ascii bigots :-( Try reading the docs for email.charset (that's the charset module in the email package). Every thing is working
Re: Characters aren't displayed correctly
On Mar 3, 1:54 pm, John Machin sjmac...@lexicon.net wrote: On Mar 3, 10:22 pm, Hussein B hubaghd...@gmail.com wrote: Hey, I added use_unicode and charset keyword params to the connect() method Hey, that was a brilliant idea -- I was just about to ask you to try use_unicode=True, charset=utf8 ... what were the actual values that you used? I didn't supply values for them the first times. I guessed that! I was referring to the fact that you didn't tell us what values you did eventually supply that made it generate seemingly reasonable Arabic letters in unicode!! Was it charset=utf8 that did the trick? Yes, it is utf8 Let's suppose that you used charset= ... as far as I can tell, not being a mysqldb user myself, this means that your data tables and/ or your default connection don't use as an encoding. If so, this might be an issue you might like to take up with whoever created the database that you are using. and I got the following: u'\u062f\u062e\u0648\u0644 \u0633\u0631\u064a\u0639 \u0634\u0647\u0631' So characters are getting converted successfully. I guess so -- U+06nn sure are Arabic characters :-) However as suggested above, converted from what? might be worth pursuing if you like to understand what is going on instead of just applying magic recipes ;-) Well, using the previous recipe for sending the mail:http://code.activestate.com/recipes/473810/ I got the following error: Traceback (most recent call last): File HtmlMail.py, line 52, in module s.sendmail(sender, receiver , msg.as_string()) [big snip] _handle_text self._fp.write(payload) UnicodeEncodeError: 'ascii' codec can't encode characters in position 115-118: ordinal not in range(128) Again, any ideas guys? :) That recipe appears to have been written by an ascii bigot for ascii bigots :-( Try reading the docs for email.charset (that's the charset module in the email package). Every thing is working now, I did the following: t = MIMEText(markup.encode('utf-8'), 'html', 'utf-8') Thank you all guys and especially you John, I owe you a HUGE bottle of beer :D Thanks for the kind thought, but beer decreases grey-cell count and increases girth ... I don't need any assistance with those matters :-) Cheers, John No problem John. -- http://mail.python.org/mailman/listinfo/python-list
Re: Characters aren't displayed correctly
On Mar 1, 4:51 pm, Philip Semanchuk phi...@semanchuk.com wrote: On Mar 1, 2009, at 8:31 AM, Hussein B wrote: Hey, I'm retrieving records from MySQL database that contains non english characters. Then I create a String that contains HTML markup and column values from the previous result set. + markup = u'''table.''' for row in rows: markup = markup + 'trtd' + row['id'] markup = markup + '/table + Then I'm sending the email according to this tip: http://code.activestate.com/recipes/473810/ Well, the email contains ? characters for each non english ones. Any ideas? There's so many places where this could go wrong and you haven't narrowed down the problem. Are the characters stored in the database correctly? Yes they are. Are they stored consistently (i.e. all using the same encoding, not some using utf-8 and others using iso-8859-1)? Yes. What are you getting out of the database? Is it being converted to Unicode correctly, or at all? I don't know, how to make sure of this point? Are you sure that the program you're using to view the email understands the encoding? Yes. Isolate those questions one at a time. Add some debugging breakpoints. Ensure that you have what you think you have. You might not fix your problem, but you will make it much smaller and more specific. Good luck Philip -- http://mail.python.org/mailman/listinfo/python-list
Re: Characters aren't displayed correctly
On Mar 1, 11:27 pm, J. Clifford Dyer j...@sdf.lonestar.org wrote: On Sun, 2009-03-01 at 09:51 -0500, Philip Semanchuk wrote: On Mar 1, 2009, at 8:31 AM, Hussein B wrote: Hey, I'm retrieving records from MySQL database that contains non english characters. Then I create a String that contains HTML markup and column values from the previous result set. + markup = u'''table.''' for row in rows: markup = markup + 'trtd' + row['id'] markup = markup + '/table + Then I'm sending the email according to this tip: http://code.activestate.com/recipes/473810/ Well, the email contains ? characters for each non english ones. Any ideas? There's so many places where this could go wrong and you haven't narrowed down the problem. Are the characters stored in the database correctly? Are they stored consistently (i.e. all using the same encoding, not some using utf-8 and others using iso-8859-1)? What are you getting out of the database? Is it being converted to Unicode correctly, or at all? Are you sure that the program you're using to view the email understands the encoding? Isolate those questions one at a time. Add some debugging breakpoints. Ensure that you have what you think you have. You might not fix your problem, but you will make it much smaller and more specific. Good luck Philip Let me add to that checklist: Are you sure the email you are creating has the encoding declared properly in the headers? -- http://mail.python.org/mailman/listinfo/python-list Cheers, Cliff My HTML markup contains only table tags (you know, table, tr and td) -- http://mail.python.org/mailman/listinfo/python-list
Re: Characters aren't displayed correctly
On Mar 2, 4:03 pm, J. Clifford Dyer j...@sdf.lonestar.org wrote: On Mon, 2009-03-02 at 00:33 -0800, Hussein B wrote: On Mar 1, 11:27 pm, J. Clifford Dyer j...@sdf.lonestar.org wrote: On Sun, 2009-03-01 at 09:51 -0500, Philip Semanchuk wrote: On Mar 1, 2009, at 8:31 AM, Hussein B wrote: Hey, I'm retrieving records from MySQL database that contains non english characters. Then I create a String that contains HTML markup and column values from the previous result set. + markup = u'''table.''' for row in rows: markup = markup + 'trtd' + row['id'] markup = markup + '/table + Then I'm sending the email according to this tip: http://code.activestate.com/recipes/473810/ Well, the email contains ? characters for each non english ones. Any ideas? There's so many places where this could go wrong and you haven't narrowed down the problem. Are the characters stored in the database correctly? Are they stored consistently (i.e. all using the same encoding, not some using utf-8 and others using iso-8859-1)? What are you getting out of the database? Is it being converted to Unicode correctly, or at all? Are you sure that the program you're using to view the email understands the encoding? Isolate those questions one at a time. Add some debugging breakpoints. Ensure that you have what you think you have. You might not fix your problem, but you will make it much smaller and more specific. Good luck Philip Let me add to that checklist: Are you sure the email you are creating has the encoding declared properly in the headers? Cheers, Cliff My HTML markup contains only table tags (you know, table, tr and td) Ah. The issue is not with the HTML markup, but the email headers. For example, the email you sent me has a header that says: Content-type: text/plain; charset=iso-8859-1 Guessing from the recipe you linked to, you probably need something like: msgRoot['Content-type'] = 'text/plain; charset=utf-16' replacing utf-16 with whatever encoding you have encoded your email with. Or it may be that the header has to be attached to the individual mime parts. I'm not as familiar with MIME. Cheers, Cliff Hey Cliff, I tried your tip and I still get the same thing (?) I added print statement to print each value of the result set into the console, which also prints characters instead of the real characters values. Maybe a conversion is happened upon getting the data from the database? (the values are stored correctly in the database) -- http://mail.python.org/mailman/listinfo/python-list
Re: Characters aren't displayed correctly
On Mar 2, 4:31 pm, John Machin sjmac...@lexicon.net wrote: On Mar 2, 7:30 pm, Hussein B hubaghd...@gmail.com wrote: On Mar 1, 4:51 pm, Philip Semanchuk phi...@semanchuk.com wrote: On Mar 1, 2009, at 8:31 AM, Hussein B wrote: Hey, I'm retrieving records from MySQL database that contains non english characters. Can you reveal which language??? Arabic Then I create a String that contains HTML markup and column values from the previous result set. + markup = u'''table.''' for row in rows: markup = markup + 'trtd' + row['id'] markup = markup + '/table + Then I'm sending the email according to this tip: http://code.activestate.com/recipes/473810/ Well, the email contains ? characters for each non english ones. Any ideas? There's so many places where this could go wrong and you haven't narrowed down the problem. Are the characters stored in the database correctly? Yes they are. How do you KNOW that they are stored correctly? What makes you so sure? Because MySQL Query Browser displays them correctly, in addition I use BIRT as the reporting system and it shows them correctly. Are they stored consistently (i.e. all using the same encoding, not some using utf-8 and others using iso-8859-1)? Yes. So what is the encoding used to store them? Tables are created with UTF-8 encoding option What are you getting out of the database? Is it being converted to Unicode correctly, or at all? I don't know, how to make sure of this point? You could show us some of the output from the database query. As well as print the_output you should print repr(the_output) and show us both, and also tell us what you *expect* to see. The result of print repr(row['name']) is '??? ??' The '?' characters are supposed to be Arabic characters. And let's get the database output sorted out before we worry about the email message. Thanks all for help. -- http://mail.python.org/mailman/listinfo/python-list
Characters aren't displayed correctly
Hey, I'm retrieving records from MySQL database that contains non english characters. Then I create a String that contains HTML markup and column values from the previous result set. + markup = u'''table.''' for row in rows: markup = markup + 'trtd' + row['id'] markup = markup + '/table + Then I'm sending the email according to this tip: http://code.activestate.com/recipes/473810/ Well, the email contains ? characters for each non english ones. Any ideas? Ubuntu 8.04 Python 2.5.2 Evolution Mail Client Thanks. -- http://mail.python.org/mailman/listinfo/python-list
What is wrong in my list comprehension?
Hey, I have a log file that doesn't contain the word Haskell at all, I'm just trying to do a little performance comparison: ++ from datetime import time, timedelta, datetime start = datetime.now() print start lines = [line for line in file('/media/sda4/Servers/Apache/ Tomcat-6.0.14/logs/catalina.out') if line.find('Haskell')] print 'Number of lines contains Haskell = ' + str(len(lines)) end = datetime.now() print end ++ Well, the script is returning the whole file's lines number !! What is wrong in my logic? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
How to start a transaction?
Hey, I know the basics of interacting with databases in Python. How to start a transaction in case I want to group a couple of insert and update statements into a single operation? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Why I'm getting the date of yesterday
Hey, I'm trying to get the get the date before today, I tried this: d = datetime.now() - timedelta(days = -1) But I got the date of tomorrow. when I tried: d = datetime.now() + timedelta(days = -1) I got the date of yesterday. Would you please explain to me why I got the date of yesterday when I added the both objects? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
How to get first/last day of the previous month?
Hey, I'm creating a report that is supposed to harvest the data for the previous month. So I need a way to get the first day and the last day of the previous month. Would you please tell me how to do this? Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get first/last day of the previous month?
On Jan 20, 5:04 pm, Carsten Haese carsten.ha...@gmail.com wrote: Hussein B wrote: Hey, I'm creating a report that is supposed to harvest the data for the previous month. So I need a way to get the first day and the last day of the previous month. In order to not deprive you of the sense of accomplishment from figuring things out for yourself, I'll give you a couple of hints instead of fully formed Python code: 1) Think about how you can find the first day of the *current* month. 2) Think about how you can get to the last day of the previous month from there. 3) Think about how you can get to the first day of the previous month from there. Hope this helps, -- Carsten Haesehttp://informixdb.sourceforge.net Thanks all for the reply. Yes, I prefer to use the standard library. Talking about the third step: You told me to think how to get the first day of the previous month, well how to know if the previous month is 28, 29, 30 or 31 days? I'm new to Python, so forgive my questions. -- http://mail.python.org/mailman/listinfo/python-list
Am I interacting with the database correctly?
Hey, I'm new with database interactions in Python and I'm not sure if I'm handling the cursor and transactions correctly: cursor = db.cursor(MySQLdb.cursors.DictCursor) cursor.execute(flate_rate_pkgs_sql) rows = cursor.fetchall() #I have for loop here to iterate over rows cursor.execute() rows = cursor.fetchall() # some more cursor.execute() calls but only SQL select statements # here is another for loop that contains try block # here are cursor.execute() calls, both insert and update db.commit() # in the except code block, I use db.rollback() As you see, my script contains only one db object and one cursor object and both the db and cursor objects are used multiple times, it is ok? As you might figured, this is a script for reports :) Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Why this code is working?
Hey, Why this code is working? def f1( ): ... x = 88 ... f2(x) ... def f2(x): ... print x ... f1( ) 88 Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why this code is working?
On Jan 14, 11:55 am, Bruno Desthuilliers bruno. 42.desthuilli...@websiteburo.invalid wrote: Hussein B a écrit : Hey, Why this code is working? def f1( ): ... x = 88 ... f2(x) ... def f2(x): ... print x ... f1( ) 88 Well... Because it is correct ? What make you think it _shouldn't_ work ? Because def2 is defined after def1 in an interpreted language, not compiled. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why this code is working?
On Jan 14, 2:21 pm, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: On Wed, 14 Jan 2009 01:57:48 -0800, Hussein B wrote: Well... Because it is correct ? What make you think it _shouldn't_ work ? Because def2 is defined after def1 in an interpreted language, not compiled. Python is compiled. What do you think the c in .pyc stands for? And what do you think the compile() function does? It's just not compiled to machine code. It's compiled to byte code. -- Steven Yes I know Python programs can be compiled but when I do: python Script1.py Did Python compile Script1 into the memory? -- http://mail.python.org/mailman/listinfo/python-list
Code coverage to Python code
Hey, What is the best code coverage tool available for Python? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
What is site-packages?
Hey, What is /usr/lib/pythonx.y/site-packages folder and for what it is used usually? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: What is site-packages?
On Dec 28, 2:04 pm, Chris Rebert c...@rebertia.com wrote: On Sun, Dec 28, 2008 at 3:40 AM, Hussein B hubaghd...@gmail.com wrote: Hey, What is /usr/lib/pythonx.y/site-packages folder and for what it is used usually? I believe it's where third-party libraries are typically installed to. Cheers, Chris -- Follow the path of the Iguana...http://rebertia.com You mean like MoinMoin, Django or Pylons for example? -- http://mail.python.org/mailman/listinfo/python-list
Which PostgreSQL adapter to use?
Hey, Which Adapter to use with PostgreSQL: PyPgSQL, psycopg or PyGreSQL? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Which PostgreSQL adapter to use?
Hi, Which PostgreSQL adapter to use: PyGreSQL, PyPgSQL or psycopg? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Understanding this generator function
Hey, This is an example of a generator function: = def counter(start_at=0): count = start_at while True: val = (yield count) if val is not None: count = val else: count += 1 == count = counter(5) count.next() 5 count.send(9) 9 == I'm not able to understand how this generator function is working, would you please me (what happens when calling next/send)? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to set/get an object property
On Aug 24, 7:12 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Sun, 24 Aug 2008 12:28:53 +0200, Peter Otten wrote: Hussein B wrote: I noted that Python encourage the usage of: -- obj.prop = data x = obj.prop -- to set/get an object's property value. What if I want to run some logic upon setting/getting a property? What is Python preferred method to do so (using the new feature 'property')? I don't think __getattr__ and __setattr__ are practical (I have to code the property name into them). Hussein, I don't think you'll learn much from asking these abstract questions. At some point you have to get your hands dirty and write actual code to get a feel for the language. For example, it will then become obvious for you that property works best for individual attributes while __getattr__ and friends are more convenient if you want to treat multiple attributes the same way, attributes whose names may not even be known until runtime (think delegation). I think you are misunderstanding Hussein's question. I believe that he is using property to refer to what we would call an attribute. Naturally I could be wrong, but this is how I interpret his question. I think the actual answer to his question is that properties are the preferred way to run some logic upon setting/getting an attribute, that is, to implement getters and setters. Hussein, the Java habit of writing setters and getters for everything isn't considered good practice in Python, but if you need them, that's exactly what the property() function is for. -- Steven Thank you Steven :) -- public class JClass { private int answer; // property } -- class PyClass(object): doc __init__(self): self.answer = None -- AFAIUY (understand you), what it is called a property in Java, it is called an attribute in Python? Why Python encourages direct access to object's attributes? aren't setters/getters considered vital in OOP (encapsulation)? Thank you all for your time and help. -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to set/get an object property
On Aug 25, 4:31 am, Steven D'Aprano [EMAIL PROTECTED] wrote: On Sun, 24 Aug 2008 23:56:27 -0700, Hussein B wrote: On Aug 24, 7:12 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: I noted that Python encourage the usage of: -- obj.prop = data x = obj.prop -- to set/get an object's property value. What if I want to run some logic upon setting/getting a property? What is Python preferred method to do so (using the new feature 'property')? I don't think __getattr__ and __setattr__ are practical (I have to code the property name into them). ... I think the actual answer to his question is that properties are the preferred way to run some logic upon setting/getting an attribute, that is, to implement getters and setters. Hussein, the Java habit of writing setters and getters for everything isn't considered good practice in Python, but if you need them, that's exactly what the property() function is for. -- Steven Thank you Steven :) -- public class JClass { private int answer; // property } -- class PyClass(object): doc __init__(self): self.answer = None -- AFAIUY (understand you), what it is called a property in Java, it is called an attribute in Python? Why Python encourages direct access to object's attributes? aren't setters/getters considered vital in OOP (encapsulation)? Thank you all for your time and help. Hussein, first let me ask you to please stop using -- as a separator around code. Many News clients, including mine, expect -- on a line by itself to mean everything from here on is the writer's signature, and consequently that makes it harder to reply correctly to your posts. I had to manually copy and paste your text in order to quote it. Perhaps you could use === or +++ or *** as a separator? Now, back to your actual question... I'm not a Java coder, so the following should be read as my opinion. Python attributes are equivalent to Java _public_ properties, not private. If you can write: public class JClass { public int answer; } then that would be more or less equivalent to Python's class PyClass(object): def __init__(self): self.answer = None Yes, Python does encourage direct access to an object's attributes. The Python philosophy is we're all adults here. If coders wish to shoot themselves in the foot by accessing clearly marked private attributes, then the language can't stop them and shouldn't try. It's easy to bypass such private/public protection in C++, and harder, but still possible, in Java. The Python development team is certainly aware that such a tactic introduces some costs, by reducing encapsulation, but it also has many benefits (e.g. less boilerplate getter/setter methods, faster development time). It is their belief that such costs are worth paying in order to get the benefits. That's the philosophy of the language. Python is not trying to be Java, and Java should not try to be Python. Python does not enforce private attributes. By convention attributes starting with a single underscore are considered private -- don't touch unless you know what you're doing. Attributes starting with a double underscore are really private, and Python mangles the name to (almost) enforce it. Example: def Parrot(object): colour = 'red' # public, free to use _windspan = 15 # semi-private, use it at your own risk __species = 'Norwegian Blue' # mangled to _Parrot__species But it's quite rare to see double-underscore really private attributes in Python code. It is considered to go against the spirit of the language. I'm told that in Java it is quite difficult to change a class from using public attributes to getters/setters, and therefore many Java developers prefer to use getters/setters right from the beginning. But in Python it is very easy to change from a bare attribute to a computed property without messing up calling code. So there's no advantage to writing something like this: class Foo(object): def __init__(self): self.__x = None # private attribute def setx(self, x): # setter self.__x = x def getx(self): # getter return self.__x x = property(getx, setx) That is considered a waste of time in Python circles and is strongly discouraged. You should read Python Is Not Java and Java Is Not Python Either: http://dirtsimple.org/2004/12/python-is-not-java.html http://dirtsimple.org/2004/12/java-is-not-python-either.html -- Steven Thank you all guys and big thank you Steven, I owe you a beer. Sorry, I wasn't aware of the two dashes problem as I use Google Group/ Reader. comp.lang.python really rocks much more friendly and useful than comp.lang.ruby -- http://mail.python.org/mailman/listinfo/python-list
No method overloading
Hey, Please correct me if I'm wrong but Python doesn't support method overload, right? -- def method(self): #code def method(self, data): #code -- The last declaration of method() erase the previous one (like JavaScript). Thanks. -- http://mail.python.org/mailman/listinfo/python-list
What is class method?
Hi, I'm familiar with static method concept, but what is the class method? how it does differ from static method? when to use it? -- class M: def method(cls, x): pass method = classmethod(method) -- Thank you for your time. -- http://mail.python.org/mailman/listinfo/python-list
Best way to set/get an object property
Hey, I noted that Python encourage the usage of: -- obj.prop = data x = obj.prop -- to set/get an object's property value. What if I want to run some logic upon setting/getting a property? What is Python preferred method to do so (using the new feature 'property')? I don't think __getattr__ and __setattr__ are practical (I have to code the property name into them). Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to set/get an object property
On Aug 24, 5:28 am, Peter Otten [EMAIL PROTECTED] wrote: Hussein B wrote: I noted that Python encourage the usage of: -- obj.prop = data x = obj.prop -- to set/get an object's property value. What if I want to run some logic upon setting/getting a property? What is Python preferred method to do so (using the new feature 'property')? I don't think __getattr__ and __setattr__ are practical (I have to code the property name into them). Hussein, I don't think you'll learn much from asking these abstract questions. At some point you have to get your hands dirty and write actual code to get a feel for the language. For example, it will then become obvious for you that property works best for individual attributes while __getattr__ and friends are more convenient if you want to treat multiple attributes the same way, attributes whose names may not even be known until runtime (think delegation). Peter Thanks Peter, You are right, I have to try to touch the Python but the problem is I don't have much time to do so. I have a Java developer for more than 4 years and I find it is not so easy to digest Python concepts, this is why I'm asking a lot of obvious and clear easy to you (long time Pythonists). Thank you for your time. -- http://mail.python.org/mailman/listinfo/python-list
Is my thinking Pythonic?
Hey, Well, as you all know by now, I'm learning Python :) One thing that is annoying my is the OOP in Python. Consider this code in Java: -- public class Car { private int speed; private String brand; // setters getters } -- With one look at the top of the class, you can know that each instance has two instance variables (speed brand). I tried to transform in into Python: -- class Car: def setspeed(self, speed): self.speed = speed def setbrand(self, brand): self.brand = brand -- If you have a huge class, you can't figure the instance variables of each object. So, I created this constructor: -- def __init__(self): self.speed = None self.brand = None -- This way, I can figure the instance variables by just reading the __init__ method. What do you think of my approach? is it considered Pythonic? Any suggestions? Thank you all. -- http://mail.python.org/mailman/listinfo/python-list
Basic importing question
Hey, Suppose I have a Python application consists of many modules (lets say it is a Django application). If all the modules files are importing sys module, how many times the sys module will be compiled and executed? Only once (the first time the PVM locates, compiles and executes the sys module)? or once for each module importing sys? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Basic importing question
On Aug 20, 5:43 am, John Machin [EMAIL PROTECTED] wrote: On Aug 20, 8:08 pm, Hussein B [EMAIL PROTECTED] wrote: Hey, Suppose I have a Python application consists of many modules (lets say it is a Django application). If all the modules files are importing sys module, how many times the sys module will be compiled and executed? Only once (the first time the PVM locates, compiles and executes the sys module)? or once for each module importing sys? Thanks. sys is a built-in module, so the answer is zero times. For a non-builtin module foo where there exists: (1) only a foo.py, it will be compiled into foo.pyc (2) only a foo.pyc, it will be used (3) both a foo.py and a foo.pyc, Python compiles the foo.py if the pyc is out of date or (so I believe [*]) was created by a different version of Python. Subsequent imports will use the in-memory copy (in sys.modules, IIRC [*]) ... [*] == Please save me the bother of checking this in the manual :-) HTH, John Thank you both for your kind help and patience :) Built-in modules are compiled but even if they are so, when importing them (sys for example), Python will run their code in order to create bindings and objects, right? I'm learning Python and I want to learn it well, so that I'm asking a lot :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Basic importing question
On Aug 20, 5:43 am, John Machin [EMAIL PROTECTED] wrote: On Aug 20, 8:08 pm, Hussein B [EMAIL PROTECTED] wrote: Hey, Suppose I have a Python application consists of many modules (lets say it is a Django application). If all the modules files are importing sys module, how many times the sys module will be compiled and executed? Only once (the first time the PVM locates, compiles and executes the sys module)? or once for each module importing sys? Thanks. sys is a built-in module, so the answer is zero times. For a non-builtin module foo where there exists: (1) only a foo.py, it will be compiled into foo.pyc (2) only a foo.pyc, it will be used (3) both a foo.py and a foo.pyc, Python compiles the foo.py if the pyc is out of date or (so I believe [*]) was created by a different version of Python. Subsequent imports will use the in-memory copy (in sys.modules, IIRC [*]) ... [*] == Please save me the bother of checking this in the manual :-) HTH, John One more question: If I have this structure: orig/com/domain/project/Klass1.py Klass2.py __init__.py Why com, domain, project should have __init__.py also? they don't contain source code files? Thanks again. -- http://mail.python.org/mailman/listinfo/python-list
Re: Basic importing question
On Aug 20, 6:39 am, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: Hussein B a écrit : (snip) One more question: If I have this structure: orig/com/domain/project/Klass1.py Klass2.py __init__.py Why com, domain, project should have __init__.py also? Yes, why should they ? Unless you want to mimic Java's package system so you do import com.domain.project.stuff - which is IMHO a pretty bad idea -, there's just no reason to turn all your filesystem into a python package. Python's philosophy here is that flat is better than nested. Sorry I don't follow you :( Module package is also nested. -- http://mail.python.org/mailman/listinfo/python-list
Question regarding the standard library?
Hey, Is the standard library of Python is compiled (you know, the pyc thing)? Is it allowed to edit the source code of the standard library? I'm not talking about submitting the modified code to Python source code repository, I'm just asking if some one can edit the source code in his own machine. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Question regarding the standard library?
On Aug 19, 7:16 am, Fredrik Lundh [EMAIL PROTECTED] wrote: Hussein B wrote: Is the standard library of Python is compiled (you know, the pyc thing)? Is it allowed to edit the source code of the standard library? I'm not talking about submitting the modified code to Python source code repository, I'm just asking if some one can edit the source code in his own machine. Python ships with the library sources, and you can of course edit them in exactly the same way as you'll edit any other Python file. modules in the standard library are no different from your own modules in that respect. whether it's a good idea to edit them (unless you're trying to track down bugs or provide patches to the maintainers) is a different issue. /F Thanks. Is the standard library compiled? -- http://mail.python.org/mailman/listinfo/python-list
Eggs and Gems
Hey, Are Python eggs and RubyGems do the same thing (of course Gems is for Ruby and eggs is for Python)? If yes, is it outstanding as the RubyGems? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Question regarding the standard library?
On Aug 19, 8:10 am, George Sakkis [EMAIL PROTECTED] wrote: On Aug 19, 8:16 am, Fredrik Lundh [EMAIL PROTECTED] wrote: Hussein B wrote: Is the standard library of Python is compiled (you know, the pyc thing)? Is it allowed to edit the source code of the standard library? I'm not talking about submitting the modified code to Python source code repository, I'm just asking if some one can edit the source code in his own machine. Python ships with the library sources, and you can of course edit them in exactly the same way as you'll edit any other Python file. modules in the standard library are no different from your own modules in that respect. whether it's a good idea to edit them (unless you're trying to track down bugs or provide patches to the maintainers) is a different issue. /F A less invasive approach is monkey-patching [1], i.e. extend or modify the runtime behavior without altering the original source code. For instance I recently needed to patch the bug posted athttp://bugs.python.org/issue1651995and I didn't have write access to the standard library, so I monkeypatched SGMLParser: # XXX: monkeypatch SGMLParser to fix bug introduced in 2.5 #http://bugs.python.org/issue1651995 if sys.version_info[:2] == (2,5): from sgmllib import SGMLParser SGMLParser.convert_codepoint = lambda self,codepoint: unichr(codepoint) HTH, George [1]http://en.wikipedia.org/wiki/Monkey_patch Hmmm, nice to know about it :) -- http://mail.python.org/mailman/listinfo/python-list
Re: You advice please
On Aug 15, 10:05 am, Bruno Desthuilliers [EMAIL PROTECTED] wrote: Hussein B a écrit : (snip) But this critisim looks so serious: http://en.wikipedia.org/wiki/Ruby_programming_language#Criticism Most of what's written here could apply to Python too - all the part which mostly reflects the usual paranoïa from bondagediscipline langages addicts wrt/ dynamic languages. The remaining is about implementation issues in ruby 1.8. Ruby doesn't has the language specification, do you think this is an issue or a weak point? -- http://mail.python.org/mailman/listinfo/python-list
AOP in Python
Hey, AOP is build in Groovy language via many means, does Python support AOP out of the box without the need for such tools: http://pythonsource.com/open-source/aspect-oriented-frameworks Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: You advice please
On Aug 13, 8:08 am, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: Hussein B a écrit : (snip) Personally, I don't like the RoR framework at all. It doesn't come with any thing new or revolutionary, You could say the same about Python and about Django. None of them come with anything new or revolutionary. And both have warts too. they just take the hard lessons from the Java web applications world. I think Ruby was a dead language and RoR gave it a life kiss. Ruby was a slowly growing language (wrt/ exposure at least) before Rails became the new buzz in town. But it was certainly not dead. Yes but Python is a known language and used by many big names (Google and NASA should be more than enough examples). Ruby on the other hand was hardly being hear, it lacks the documentation, a specification and an umbrella like JCP or PSF. I'm not sure why The Pragmatic Programmer and Manning publishers aren't doing any work on Python. Well, the Python bit me :) -- http://mail.python.org/mailman/listinfo/python-list
Re: You advice please
On Aug 13, 11:14 am, Alia Khouri [EMAIL PROTECTED] wrote: Hussein B wrote: I'm a Java/Java EE developer and I'm playing with Python these days. I like the Python language so much and I like its communities and the Django framework. Sounds familiar... (-: My friends are about to open a Ruby/Rails shop and they are asking me to join them. In this case, I think you have to make decision that is not technology- centric but application-centric, and you should also consider closely the opportunity set and capability set available to you and your friends. I don't know what, sure I'm not leaving Java, but they are asking me to stop learning Python and concentrate on Ruby/Rails. I don't think you should stop learning anything that rings your bell.. I love learning other languages (e.g. Haskell, Lua, Ruby, C#, Java, boo, etc..) and I will code projects as per the requirements at the time, but I tend to Python because, like you, I like the language and the community. In _addition_ to your love for Python and Django, why not learn Ruby/ Rails? It's not a bad framework at all, and Ruby is quite fun to program in as well...? The sad fact (at least to me), Ruby is getting a lot of attention these days. Not a sad fact, What's good for ruby is good for python and vice versa... Friendly competition is always positive and usually good ideas cross-pollinate across the languages... Why Python isn't getting this attention although is a much more mature language and it is used by many big, big names? Who says Python is not getting attention? Last time I checked, Python's popularity was at all time high, and the big guns in the industry favor (witness Google AppEngine, Microsoft Ironpython preceding Ironruby, etc..) And do I dare to say it is much more charming? That is an aesthetic judgement... (-: What do you think of Ruby/Rails? do they worth learning and working with? (see above) Any way, I'm not leaving Python and I will try to study it every time I get a chance... Good for you (-: Thanks. But this critisim looks so serious: http://en.wikipedia.org/wiki/Ruby_programming_language#Criticism -- http://mail.python.org/mailman/listinfo/python-list
You advice please
Hey, I'm a Java/Java EE developer and I'm playing with Python these days. I like the Python language so much and I like its communities and the Django framework. My friends are about to open a Ruby/Rails shop and they are asking me to join them. I don't know what, sure I'm not leaving Java, but they are asking me to stop learning Python and concentrate on Ruby/Rails. The sad fact (at least to me), Ruby is getting a lot of attention these days. Why Python isn't getting this attention although is a much more mature language and it is used by many big, big names? And do I dare to say it is much more charming? What do you think of Ruby/Rails? do they worth learning and working with? Any way, I'm not leaving Python and I will try to study it every time I get a chance... Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: You advice please
On Aug 13, 6:51 am, Jeroen Ruigrok van der Werven [EMAIL PROTECTED] nomine.org wrote: -On [20080813 13:16], Hussein B ([EMAIL PROTECTED]) wrote: My friends are about to open a Ruby/Rails shop and they are asking me to join them. I hope they are fully aware of the scaling problems RoR can have. Why Python isn't getting this attention although is a much more mature language and it is used by many big, big names? At least in my experience Python is getting more and more exposure. More job openings as well. -- Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org / asmodai イェルーン ラウフロック ヴァン デル ウェルヴェンhttp://www.in-nomine.org/|http://www.rangaku.org/| GPG: 2EAC625B A liar needs a good memory... So do you advice me to join them? -- http://mail.python.org/mailman/listinfo/python-list
Re: You advice please
On Aug 13, 7:40 am, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: Álvaro G. Vicario a écrit : Hussein B escribió: The sad fact (at least to me), Ruby is getting a lot of attention these days. Why Python isn't getting this attention although is a much more mature language and it is used by many big, big names? And do I dare to say it is much more charming? The opinion of a PHP developer who's playing with Python as well: I've come across Python almost everywhere. Many programs I use (or I've evaluated) are written in Python or use it for scripting: source control software (Subversion, Bazaar, Mercurial), IDEs (Komodo Edit), popular web applications (Zope, Trac)... If you're looking for a script for admin tasks your search results will probably contain something in Python. If you want to build a Firefox extension you'll find a *.py file sitting around. But I've never came across a Ruby app. Sure, I know Ruby exists and people are very enthusiastic about it (though they often mistake it with Ruby on Rails), but that's all. Redmine is a nice alternative to Trac. And Twitter is certainly a well-known app too. (Yes, RoR apps in both cases...). Ruby is popular among bloggers but I'm not sure whether it's popular among developers. Almost as much as Python, I'd say. But both languages fight for the same niches in languages/techno ecosystem, and Python, being older, tend to get more visibility. But Twitter is suffering from sever scaling problems, I read it maybe will be reimplemented in Java ... -- http://mail.python.org/mailman/listinfo/python-list
Re: You advice please
On Aug 13, 7:50 am, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: Hussein B a écrit : Hey, I'm a Java/Java EE developer and I'm playing with Python these days. I like the Python language so much and I like its communities and the Django framework. My friends are about to open a Ruby/Rails shop and they are asking me to join them. I don't know what, sure I'm not leaving Java, but they are asking me to stop learning Python and concentrate on Ruby/Rails. The sad fact (at least to me), Ruby is getting a lot of attention these days. Why Python isn't getting this attention although is a much more mature language and it is used by many big, big names? RoR peoples are good at marketing. And Ruby's object model is probably less alien - at least at first sight - to the Java crowd than Python's object model is. But still, Python seems to get some serious exposure - at least outside of the Java world - these last monthes. And do I dare to say it is much more charming? What do you think of Ruby/Rails? do they worth learning and working with? Both are certainly worth learning. I can't tell about the working with part since I never used any of them for anything serious. Any way, I'm not leaving Python and I will try to study it every time I get a chance... Thanks. Personally, I don't like the RoR framework at all. It doesn't come with any thing new or revolutionary, they just take the hard lessons from the Java web applications world. I think Ruby was a dead language and RoR gave it a life kiss. -- http://mail.python.org/mailman/listinfo/python-list
Continuous integration for Python projects
Hi. Please correct my if I'm wrong but it seems to me that the major continuous integration servers (Hudson, CruiseControl, TeamCity ..) don't support Python based application. It seems they mainly support Java, .NET and Ruby. Can I use one of the previous listed servers for Python project? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Build tool for Python
Hi. Apache Ant is the de facto building tool for Java (whether JSE, JEE and JME) application. With Ant you can do what ever you want: compile, generate docs, generate code, packing, deploy, connecting to remote servers and every thing. Do we have such a tool for Python projects? Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Module clarification
Hi. I'm a Java guy and I'm playing around Python these days... In Java, we organize our classes into packages and then jarring the packages into JAR files. What are modules in Python? What is the equivalent of modules in Java? Please correct me if I'm wrong: I saved my Python code under the file Wow.py Wow.py is now a module and I can use it in other Python code: import Wow Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Module clarification
On Jul 28, 6:55 am, Floris Bruynooghe [EMAIL PROTECTED] wrote: On Jul 28, 9:54 am, Hussein B [EMAIL PROTECTED] wrote: Hi. I'm a Java guy and I'm playing around Python these days... In Java, we organize our classes into packages and then jarring the packages into JAR files. What are modules in Python? An importable or runable (i.e. script) collection of classes, functions, variables etc... What is the equivalent of modules in Java? Don't know. Not even sure if it exists, but my Java is old and never been great. Please correct me if I'm wrong: I saved my Python code under the file Wow.py Wow.py is now a module and I can use it in other Python code: import Wow Indeed, you can now access things defined in Wow as Wow.foo Regards Floris If I have a couple of modules, is there a way to package them? or there is no such a thing in Python? -- http://mail.python.org/mailman/listinfo/python-list
Re: Module clarification
On Jul 28, 8:11 am, Duncan Booth [EMAIL PROTECTED] wrote: Hussein B [EMAIL PROTECTED] wrote: If I have a couple of modules, is there a way to package them? or there is no such a thing in Python? It sounds rather as though you haven't yet gone through the Python tutorial. You really should read it, even if you just skim through it to see what topics are covered. The tutorial explains both modules and packages:http://docs.python.org/tut/node8.html What it doesn't cover is that you can import modules or packages directly from a zip file. Then read about eggs. -- Duncan Boothhttp://kupuguy.blogspot.com I'm reading Learning Python, 3rd Edition What do you think about it? -- http://mail.python.org/mailman/listinfo/python-list