Executing remote command with paramiko

2009-08-03 Thread Hussein B
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,

A little help with pexpect

2009-07-19 Thread Hussein B
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

Remoting over SSH

2009-07-08 Thread Hussein B
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

2009-03-03 Thread Hussein B
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

Re: Characters aren't displayed correctly

2009-03-03 Thread Hussein B
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

Re: Characters aren't displayed correctly

2009-03-03 Thread Hussein B
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

Re: Characters aren't displayed correctly

2009-03-03 Thread Hussein B
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

Re: Characters aren't displayed correctly

2009-03-02 Thread Hussein B
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

Re: Characters aren't displayed correctly

2009-03-02 Thread Hussein B
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

Re: Characters aren't displayed correctly

2009-03-02 Thread Hussein B
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

Re: Characters aren't displayed correctly

2009-03-02 Thread Hussein B
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

Characters aren't displayed correctly

2009-03-01 Thread Hussein B
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 +

What is wrong in my list comprehension?

2009-02-01 Thread Hussein B
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/

How to start a transaction?

2009-01-20 Thread Hussein B
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

2009-01-20 Thread Hussein B
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

How to get first/last day of the previous month?

2009-01-20 Thread Hussein B
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?

2009-01-20 Thread Hussein B
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

Am I interacting with the database correctly?

2009-01-18 Thread Hussein B
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

Why this code is working?

2009-01-14 Thread Hussein B
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?

2009-01-14 Thread Hussein B
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

Re: Why this code is working?

2009-01-14 Thread Hussein B
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

Code coverage to Python code

2009-01-04 Thread Hussein B
Hey, What is the best code coverage tool available for Python? Thanks. -- http://mail.python.org/mailman/listinfo/python-list

What is site-packages?

2008-12-28 Thread Hussein B
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?

2008-12-28 Thread Hussein B
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

Which PostgreSQL adapter to use?

2008-11-04 Thread Hussein B
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?

2008-11-04 Thread Hussein B
Hi, Which PostgreSQL adapter to use: PyGreSQL, PyPgSQL or psycopg? Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Understanding this generator function

2008-08-27 Thread Hussein B
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

Re: Best way to set/get an object property

2008-08-25 Thread Hussein B
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

Re: Best way to set/get an object property

2008-08-25 Thread Hussein B
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

No method overloading

2008-08-24 Thread Hussein B
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?

2008-08-24 Thread Hussein B
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

2008-08-24 Thread Hussein B
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

Re: Best way to set/get an object property

2008-08-24 Thread Hussein B
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

Is my thinking Pythonic?

2008-08-21 Thread Hussein B
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

Basic importing question

2008-08-20 Thread Hussein B
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)?

Re: Basic importing question

2008-08-20 Thread Hussein B
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

Re: Basic importing question

2008-08-20 Thread Hussein B
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

Re: Basic importing question

2008-08-20 Thread Hussein B
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

Question regarding the standard library?

2008-08-19 Thread Hussein B
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.

Re: Question regarding the standard library?

2008-08-19 Thread Hussein B
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

Eggs and Gems

2008-08-19 Thread Hussein B
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?

2008-08-19 Thread Hussein B
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

Re: You advice please

2008-08-18 Thread Hussein B
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

AOP in Python

2008-08-18 Thread Hussein B
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

2008-08-14 Thread Hussein B
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

Re: You advice please

2008-08-14 Thread Hussein B
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

You advice please

2008-08-13 Thread Hussein B
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

Re: You advice please

2008-08-13 Thread Hussein B
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

Re: You advice please

2008-08-13 Thread Hussein B
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

Re: You advice please

2008-08-13 Thread Hussein B
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

Continuous integration for Python projects

2008-07-29 Thread Hussein B
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?

Build tool for Python

2008-07-29 Thread Hussein B
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. --

Module clarification

2008-07-28 Thread Hussein B
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

Re: Module clarification

2008-07-28 Thread Hussein B
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

Re: Module clarification

2008-07-28 Thread Hussein B
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