Hi tutors,
I've got an external program that I'm calling from python with
os.popen. The problem is that I need to pass this program an arbitrary
body of text. I've tried escaping characters before passing it as
input but the shell still expands out certain characters. I noticed
with python2.4. How
Say I have a directory tree like this:
foo
- bar
-- quux.py
- baz
-- glonk.py
>From within glonk.py, how do I import quux.py? I've tried going to
foo, running baz/glonk.py, and using "from bar import quux", but this
doesn't seem to work.
Thanks in advance!
Lawrence
lawrence wang wrote:
> Say I have a directory tree like this:
>
> foo
> - bar
> -- quux.py
> - baz
> -- glonk.py
>
>>From within glonk.py, how do I import quux.py? I've tried going to
> foo, running baz/glonk.py, and using "from bar import quux", but this
> doesn't seem to work.
You need a fil
> input but the shell still expands out certain characters. I noticed
> with python2.4. How do I bypass the shell and hand arguments
directly
> to the program?
The first thing I'd do is create the command string before passing
it to popen - that way we can debug easier by seeing exactly what
is be
Is there a way to test if a class method was called from an instance?
What I am trying to do is if a method is called from the class return
a commanding proxy with an mock or stub type object as the proxied
object. If it is called from the instance I want to return a proxy for
the instance.
Does
As a newbie developer, the easiest way for me to connect to MySQL is to
just copy & paste the connection commands into each funtion I write.
However, I know that's far from ideal, and consumes more time than its
worth. I would like to create a MySQL connection function that I can just
call up whe
This a very simple connection using mysql.
1. connect to mysql:
db = mySQLdb.connect(user='root',passwd='something')
2. To execute and get the result:
c = db.cursor()
c.execute(sql comment)
result = c.fetchall()
you can wrap it in a class object.
pujo
On 6/21/05, Don Parris <[EMAIL PROTECTED]>
Hey tutors
I have some classes I want to make available as built-in modules in Python
2.3.4 over Windows
To make myself clear in case you don't understand I have the file List.py (a
nested list C# like) and I want to be able to call the class List (which is
inside the List.py) without having to
David Driver wrote:
> Is there a way to test if a class method was called from an instance?
>
> What I am trying to do is if a method is called from the class return
> a commanding proxy with an mock or stub type object as the proxied
> object. If it is called from the instance I want to return
Alberto Troiano wrote:
> Hey tutors
>
> I have some classes I want to make available as built-in modules in Python
> 2.3.4 over Windows
> To make myself clear in case you don't understand I have the file List.py (a
> nested list C# like) and I want to be able to call the class List (which is
>
Sorry for the elementary question: I was wondering if someone could
explain the difference to me between class and static methods. Coming
from other languages, I'm used to static methods, but not "class
methods". Thanks.
--
Best regards,
Chuck
___
Tut
I'm having trouble loading an image into a Postgre database. The code is below
as well as the traceback in the apache log. Is something up with my
sqlStatement? Do I need to use something other than %s? How can I avoid that
type error?
Thanks,
Mike
#! /usr/bin/env python
import cgi
from pyP
On Tue, 21 Jun 2005 16:52:09 -0400, Chuck Allison wrote
(in article <[EMAIL PROTECTED]>):
> Sorry for the elementary question: I was wondering if someone could
> explain the difference to me between class and static methods. Coming
> from other languages, I'm used to static methods, but not "class
On Tue, 21 Jun 2005, Mike Hansen wrote:
> I'm having trouble loading an image into a Postgre database. The code is
> below as well as the traceback in the apache log. Is something up with
> my sqlStatement? Do I need to use something other than %s? How can I
> avoid that type error?
Hi Mike,
> Thankfully, you don't have to change much to fix the formatting bug. The
> only thing you'll need to do is let the SQL cursor do the value formatting
> for you:
>
> ##
> sqlStatement = """INSERT INTO images (image)
> VALUES (%s);
> cur.execute(sqlStatement, (data_obj))
> ##
Hello Chinook,
So is the main motivation for class methods so that you can have the
class object available? It seems you can have that anyway in a static
method by just asking. I'm sure there's a good reason for this, but I
haven't yet gotten to the point of mastery where I can see a need for
clas
> >print "%s\t%s" % (m,menu[m][0])
> >
> I am curious what the "%" by itself is doing.
Its a standard string formatting operation in Python.
The % operator basically says substitute the values
in the folowing tuple for the marked fields in the
foregoing string.
The print statement above th
Hey all,
how do i pause a script. like
print 'something'
pause a half second
print 'something else'
any takers?
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Ketn
You are correct.
What I will do is an instance method that calls the class method with
an optional parameter.
I don't know what I was thinking, I was just messing around with
nested classes for the first time and kind of forgot how to program.
On 6/21/05, David Driver <[EMAIL PROTECTED]>
nephish said unto the world upon 21/06/2005 20:17:
> Hey all,
> how do i pause a script. like
> print 'something'
> pause a half second
> print 'something else'
>
> any takers?
>
> ___
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailm
> worth. I would like to create a MySQL connection function that I
can just
> call up whenever I need it from within an other function.
Good idea!
> ### The Connection Definition ###
> # def mysql_Conn():
> # Create a connection object and create a cursor.
> # Con = MySQLdb.Connect(host=
> Is there a way to test if a class method was called from an
instance?
I think you'll need to override the __getattr__ method.
It will pick up the call and you can test whether its a
class mrethod being called. I think...
> What I am trying to do is if a method is called from the
> class return
> nested list C# like) and I want to be able to call the class List
(which is
> inside the List.py) without having to copy it in every folder where
I have a
> script that needs this module
>
> Can I do that?
Yes.
See Kent's reply to a similar post about creating a package.
You can also just copy
On Tue, 21 Jun 2005 17:58:09 -0400, Chuck Allison wrote
(in article <[EMAIL PROTECTED]>):
> Hello Chinook,
>
> So is the main motivation for class methods so that you can have the
> class object available? It seems you can have that anyway in a static
> method by just asking. I'm sure there's a g
-- Original Message -
Subject: Re: [Tutor] Numbers & Characters As Dictionary Keys
Date: Tue, 21 Jun 2005 17:47:41 +0100
From: "Alan G" <[EMAIL PROTECTED]>
To: "Don Parris" <[EMAIL PROTECTED]>,
"Python Tutor List"
> >print "%s\t%s" % (m,menu[m][0])
> >
> I am cur
> Sorry for the elementary question: I was wondering if someone could
> explain the difference to me between class and static methods.
Coming
> from other languages, I'm used to static methods, but not "class
> methods". Thanks.
There probably is a deep and subtle difference in Python but to
all
Chuck Allison wrote:
> Hello Chinook,
>
> So is the main motivation for class methods so that you can have the
> class object available? It seems you can have that anyway in a static
> method by just asking.
No, a classmethod is passed the class that it is called on. If you have an
inheritance t
As a newbie developer, the easiest way for me to connect to MySQL is to
> just copy & paste the connection commands into each funtion I write.
> However, I know that's far from ideal, and consumes more time than its
> worth. I would like to create a MySQL connection function that I can just
> cal
You are right to be confused because I was as well. I was shooting for:
> OR do you mean you will have an actual class method
> (ie static in C++/Java speak) and want to know if the
> activating message was sent to the class object or to
> an instance of the class?
The easiest solution was to do
On Tue, 21 Jun 2005 19:13:43 -0400
Python <[EMAIL PROTECTED]> wrote:
> I like to use the following style of code. Since there will be
> passwords, the connection strings should be somewhat protected. Put
> them in a separate file that can be controlled. Here's my sample code.
> >>
Hi I have a list of regular expression patterns like such:
thelist =
['^594694.*','^689.*','^241.*','^241(0[3-9]|1[0145]|2[0-9]|3[0-9]|41|5[1-37]|6[138]|75|8[014579]).*']
Now I want to iterate thru each of these like:
for pattern in thelist:
regex=re.compile(pattern)
if regex.match('24
Hi Wang,
You need to do what the shell does, all up the program directly, like this:
fork parent,
in the parent, reap the child
in the child, call exec() with the subprogram as the argument
Here's an example:
import os
program_executable = "/bin/ls"
parameters = ["/home/me/file1.txt", "/home/m
32 matches
Mail list logo