u just click u get some dollars

2008-07-25 Thread abcd
http://www.parttimejobsu.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Problem in Installing/using OpenOpt

2007-11-13 Thread abcd efgh
Hi,

I am facing some problem in installing the OpenOpt optimization toolbox.

What I have done is I downloaded the OpenOpt package and added the
folder containing scikits to the PythonPath by:

sys.path.append('C:\Documents and Settings\User\Desktop\openopt')

but when i try following:

from scikits.openopt import NLP

I get an error saying:

-error
message
Traceback (most recent call last):
  File "", line 1, in -toplevel-
from scikits.openopt import NLP
  File "C:\Documents and
Settings\User\Desktop\openopt\scikits\__init__.py", line 1, in
-toplevel-
__import__('pkg_resources').declare_namespace(__name__)
ImportError: No module named pkg_resources
-

Can anyone help me how can I use this package? I have to solve a non
linear programming problem.

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


unknown host

2007-06-01 Thread abcd
I have a linux machine (ip = 10.10.10.8), which can ping other
machines on the same subnet...such as

10.10.10.1
10.10.10.2
10.10.10.5
10.10.10.6
10.10.10.254

If I use socket.gethostbyaddr() I get back results when ip is
10.10.10.1 and 10.10.10.254 but for the other IP addresses
(10.10.10.5, .6, etc) I get back "unknown host".  In fact I get
"unknown host" for the linux machine that I run the gethostbyaddr
from.

If perform the same operation from a windows machine (ip = 10.10.10.5)
it returns data for the other IP addresses as expected.

any ideas?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: regular expression for parsing an html element

2007-04-20 Thread abcd
thanks, forgot that.

-- 
http://mail.python.org/mailman/listinfo/python-list


regular expression for parsing an html element

2007-04-20 Thread abcd
I have some HTML such as

blah blah blah

I wnat to pull out the text that lies inside the quotes of the src
attribute.  So in this example I would get image/blah/a.jpg

My regex so far is:  src=\"(.*)\" however the group in this case
would end up being, image/blah/a.jpg" id="d">blah blah blah.

how can I tell the regex group (.*) to end when it gets to the first
" ?

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


wrap_EncryptByteArray argument 1 must be string without null bytes, not str

2007-04-12 Thread abcd
Has anyone seen this error before:

wrap_EncryptByteArray() argument 1 must be string without null bytes,
not str

I am having a hard time finding anything about it.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Retrieve an item from a dictionary using an arbitrary object as the key

2007-04-03 Thread abcd
> You'll need __eq__ for testing if two objects are equivalent, and
> __hash__ for calculating object's hash value.
>
> class Type:
> def __init__(self, val):
> self.val = val
>
> def __eq__(self, other):
> return self.val == other.val
>
> def __hash__(self):
> return hash(self.val)

that's exactly what I needed, thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Retrieve an item from a dictionary using an arbitrary object as the key

2007-04-03 Thread abcd
Hi,
I have a class such as,

class Type:
def __init__(self, val):
self.val = val

class Person:
def __init__(self, name, age):
self.name = name
self.age = age

So I have a dictionary which maps an instance of Type to an instance
of Person.  Now I need to retrieve a particular Person given a Type
object.  What method in Type do I need to implement to allow it to be
retrieved?

For example (this is just an example):

t = Type(19)
p = Person("bob", 99)

x = {t : p}



def getPerson(val):
return x[Type(val)]

getPerson(19)  should return me the Person with name "bob" and age
99.  I am thinking there is some method that is used by the dictionary
to know if the key exists, just not sure which.

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about extending tuple

2007-03-29 Thread abcd
>
> I hope you see now why it is consistent.
>
> Georg

yea that clears it up.  thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about extending tuple

2007-03-28 Thread abcd
> As an immutable type, tuple makes use of __new__.
>
> class MyTuple(tuple):
>  def __new__(cls, *args):
>  return tuple.__new__(cls, args)
>
> should work.
>
> Georg

strange.  not very consistent.

-- 
http://mail.python.org/mailman/listinfo/python-list


Question about extending tuple

2007-03-28 Thread abcd
I wanted to extend tuple but ran into a problem.  Here is what I
thought would work

class MyTuple(tuple):
def __init__(self, *args):
tuple.__init__(self, args)

x = MyTuple(1,2,3,4)

That gives me...

TypeError: tuple() takes at most 1 argument (4 given).

However, this call works:

x = MyTuple((1,2,3,4))

I am perplexed only because "args" is a tuple by the definition of
*args.  Anyone?

-- 
http://mail.python.org/mailman/listinfo/python-list


Make variable global

2007-03-21 Thread abcd
I have a file, "a.py"

blah = None
def go():
global blah
blah = 5

>From the python interpreter I try

>>> from a import *
>>> blah
>>> go()
>>> blah
>>>

...i was hoping to see "5" get printed out the second time I displayed
blah, but it doesn't.  Now, if I type this same code directly into the
python interpreter it works as i was hoping.  what i am missing?

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help - Module needs access to another module

2007-03-20 Thread abcd
On Mar 20, 9:58 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> After a bunch of questions of that kind, I suggest you take a step back, and
> read this:
>
> http://docs.python.org/tut/node8.html


got it, thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


help - Module needs access to another module

2007-03-20 Thread abcd
I have the following directory/file structure...

c:\foo\utils.py
c:\foo\bar\ok.py

In ok.py I want to do something like...

import utils
utils.helpMeDoSomething()

However, it seems that ok.py doesn't "know" about utils.  Other than
manually configuring sys.path what can I do?

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Load three different modules which have the same name

2007-03-20 Thread abcd
thanks for the help.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Load three different modules which have the same name

2007-03-20 Thread abcd
> Blerch! Why not just call the modules by the right names in the first
> place? Then each will have its own sys.modules entry for a start ...
>
> regards
>   Steve

what do i need to do?  also, is there a way I can load each one as I
have but each one have its own unique entry in sys.modules?  For
example i could load Person from Person (in alpha) as, "Person_Alpha"
or something like that in sys.modules?  not sure how I might do that.

Thanks!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Load three different modules which have the same name

2007-03-19 Thread abcd
nevermind this took care of it:

import sys

def tryAllThree():
a = "c:\\alpha"
b = "c:\\beta"
g = "c:\\gamma"

sys.path.append(a)
import Person
alpha = Person.Person()

sys.path.remove(a)
sys.path.append(b)
reload(Person)
beta = Person.Person()

sys.path.remove(b)
sys.path.append(g)
reload(Person)
gamma = Person.Person()

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Load three different modules which have the same name

2007-03-19 Thread abcd
I have the following directory structure setup...

c:\alpha\Person.py
--
class Person(IPerson):
def __init__(self):
print "Alpha person here"

c:\beta\Person.py
--
class Person(IPerson):
def __init__(self):
print "Beta person here"

c:\gamma\Person.py
--
class Person(IPerson):
def __init__(self):
print "Gamma person here"

c:\ok\playground.py
---
def tryAllThree():
a = "c:\\alpha"
b = "c:\\beta"
g = "c:\\gamma"

sys.path.append(a)
from Person import Person
alpha = Person()

sys.path.remove(a)
sys.path.append(b)
from Person import Person
beta = Person()

sys.path.remove(b)
sys.path.append(g)
from Person import Person
gamma = Person()

Notice that my three different projects (alpha, beta, gamma) have a
Person.py which contains a Person class.

When I execute the following (on windows):

c:\ok> python
>>> from playground import *
>>> tryAllThree()

I see...
Alpha person here
Alpha person here
Alpha person here

What I want to see is
Alpha person here
Beta person here
Gamma person here

how can I get this to work?

Thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Multiline code - trailing slash usage

2007-03-15 Thread abcd
When do I need to use a trailing slash to separate code over multiple
lines.

For example:

x = "hello world, this is my multiline " + \
 "string"

x = {'name' : \
  'bob'}

Do I need to use the "\" in the above examples?  When do i need to use
it?

-- 
http://mail.python.org/mailman/listinfo/python-list


wxTextCtrl - copy and paste 65, 000 characters of text into it only seems to hold 30, 003

2007-03-15 Thread abcd
I have a wxTextCtrl:

wx.TextCtrl(self.myPanel, -1, "", style=wx.TE_MULTILINE)

I take a set of text (65,000 characters), and paste it into the text
control.  all looks well.  Then when I click a button I print out the
entered text and the length of that text.  Here is what I am seeing...

1. Paste in text (65,000 characters)
2. Click button
3. Output on screen shows that the message length (i.e. len(msg)) is
30003  (strange since it should be 65000)
4. Select all text in the text control and hit delete.  The text
control should now be empty.
5. Paste in text (65,000 characters)
6. Click Button
7. Output on screen shows that the message length (i.e. len(msg)) is
65000 (as expected).

Any idea why the first time it gives me 30003, but on subsequent
attempts I get 65000?

Thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Quick Filter Dictionary

2007-03-14 Thread abcd
On Mar 14, 7:29 am, "abcd" <[EMAIL PROTECTED]> wrote:
> Hi,
>I have a dictionary which may contain various keys/values, however,
> it will always contain 'name' and 'age' keys.
>
>This dictionary is kept inside a class, such as
>
> class Person:
> def __init__(self, name, age):
> self.data = {'name' : name, 'age' : age}
>
> def getData(self, includeNameAge=False):
> if includeNameAge: return self.data
> tmp = 
> del tmp['name']
> del tmp['age']
> return tmp
>
>The getdata method should return the data stored for the
> person, however, it should be able to return the data excluding the
> 'name' and 'age'.  Any suggestions on how to best implement this?
> Keep in mind this sample code is meant to be an example, I realize
> that a person would probably always want the name and age returned.
>
> thanks


I guess one solution might be

def getData(self, includeNameAge=False):
if includeNameAge: return self.data
return dict(filter(lambda item: item[0] not in ('name', 'age'),
self.data.items()))

any other suggestions, improvements?

-- 
http://mail.python.org/mailman/listinfo/python-list


Quick Filter Dictionary

2007-03-14 Thread abcd
Hi,
   I have a dictionary which may contain various keys/values, however,
it will always contain 'name' and 'age' keys.

   This dictionary is kept inside a class, such as

class Person:
def __init__(self, name, age):
self.data = {'name' : name, 'age' : age}

def getData(self, includeNameAge=False):
if includeNameAge: return self.data
tmp = 
del tmp['name']
del tmp['age']
return tmp

   The getdata method should return the data stored for the
person, however, it should be able to return the data excluding the
'name' and 'age'.  Any suggestions on how to best implement this?
Keep in mind this sample code is meant to be an example, I realize
that a person would probably always want the name and age returned.

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to Start a (thread?) and Leave

2007-03-09 Thread abcd
> But a thread leaves the script running until the thread exits, right?
> So the webpage would just keep saying "loading" at the bottom I think.
>
> -Greg

give it a shot.  if you spawn off a new thread your code should keep
executing while the thread does its work in the "background".

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to Start a (thread?) and Leave

2007-03-09 Thread abcd
probably a Thread.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Are Lists thread safe?

2007-03-09 Thread abcd
On Mar 9, 2:50 pm, "abcd" <[EMAIL PROTECTED]> wrote:
> I guess this might be overkill then...
>
> class MyList(list):
> def __init__(self):
> self.l = threading.Lock()
>
> def append(self, val):
> try:
> self.l.acquire()
> list.append(self, val)
> finally:
> if self.l.locked():
> self.l.release()
>
> performing the same locking/unlocking for the other methods (i.e.
> remove, extend, etc).

comments?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Are Lists thread safe?

2007-03-09 Thread abcd
I guess this might be overkill then...

class MyList(list):
def __init__(self):
self.l = threading.Lock()

def append(self, val):
try:
self.l.acquire()
list.append(self, val)
finally:
if self.l.locked():
self.l.release()

performing the same locking/unlocking for the other methods (i.e.
remove, extend, etc).

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Are Lists thread safe?

2007-03-09 Thread abcd
Thanks for the link.  I saw that one in my google search but didn't
visit it for some reason.

Looks like most operations should be just fine.

Thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Are Lists thread safe?

2007-03-09 Thread abcd
Are lists thread safe?  Or do I have to use a Lock when modifying the
list (adding, removing, etc)?  Can you point me to some documentation
on this?

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyHook or SetWindowsHookEx

2007-03-02 Thread abcd
:(

-- 
http://mail.python.org/mailman/listinfo/python-list


Capture key strokes

2007-03-01 Thread abcd
Is there a way to capture key strokes on a system using python (other
than pyHook)?  can wxPython capture keystrokes for the system (not
just, say a text box)?

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyHook or SetWindowsHookEx

2007-02-28 Thread abcd
anyone?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: book for a starter

2007-02-27 Thread abcd
I'd pick, Dive Into Python (http://www.diveintopython.org/) you
can read it online for FREE!

-- 
http://mail.python.org/mailman/listinfo/python-list


pyHook or SetWindowsHookEx

2007-02-27 Thread abcd
I am having trouble with pyHook on python 2.4.1.  Basically I have a
python app that uses pyHook to capture keyboard events and write them
straight to a file.  The application is running as a service on a
windows machine.  If I am at that windows machine the application
works just fine, logging my keystrokes.  However, if I use Remote
Desktop to connect to the machine and open up say Notepad it doesn't
capture the keystrokes.  Is this a problem with pyHook?  or is it he
way Windows handles the events?

Is there a way to setup my own hook without pyHook using just python?
i think the function I am interested in is SetWindowsHookEx.

Thanks in advance.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: marshal.loads ValueError

2007-01-31 Thread abcd
On Jan 31, 8:02 am, Benjamin Niemann <[EMAIL PROTECTED]> wrote:
> marshal is used to (de)serialize python objects from/to strings.
> marshal.loads() tries to deserialize an encoded string back into a python
> object - which does not make sense here.
> What you probably want is:
>
> exec data in my_module.__dict__

thanks that took care of it.

-- 
http://mail.python.org/mailman/listinfo/python-list


marshal.loads ValueError

2007-01-31 Thread abcd
I have the following code which is sent over the wire as a string...

from time import time
class Foo:
def go(self):
print "Time:", time()


I get this code and store it as, "data"

data = receivePythonSource()

Then I try...

exec marshal.loads(data) in my_module.__dict__

However I get an error saying:
ValueError: invalid literal for __float__: om time import time
class Foo:
def go(self):

almost like when I try to marshal and exec it misses the first two
characters, "fr" ...any ideas?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Thoughts on using isinstance

2007-01-24 Thread abcd
>Yes because usually you don't expect a list or dictionary but some object
> that *acts* like a list or dictionary.  Or you even expect just some
> aspects of the type's behavior.  For example that it is something you can
> iterate over.
>
> Ciao,
> Marc 'BlackJack' Rintsch

good point.  is there place that documents what methods/attrs I should
check for on an object?  for example, if its a list that I expect I
should verify the object that is passed in has a ??? function? etc.

thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Thoughts on using isinstance

2007-01-24 Thread abcd
Well my example function was simply taking a string and printing, but
most of my cases would be expecting a list, dictionary or some other
custom object.  Still propose not to validate the type of data being
passed in?

Thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Thoughts on using isinstance

2007-01-24 Thread abcd
Well my example function was simply taking a string and printing, but
most of my cases would be expecting a list, dictionary or some other
custom object.  Still propose not to validate the type of data being
passed in?

Thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Thoughts on using isinstance

2007-01-24 Thread abcd
> The "Python way" is to validate by performing the operations you need to
> perform and catching any exceptions that result. In the case of your
> example, you seem to be saying that you'd rather raise your own
> exception (which, by the way, should really be a subclass of Exception,
> but we will overlook that) that relying on the interpreter to raise a
> ValueError or a TypeError. Is there really any advantage to this? You
> increase your code size and add *something* to execution time with
> little real purpose.
>
> People coming to Python after C++ or some similar language that allows
> or requires parameter type declarations often don't feel comfortable
> taking this direction to start with, but  it works well for most of us.
>
> regards
>   Steve


So instead of validating input I should just try and use the input as
if it was correct, and let python throw the errors?

-- 
http://mail.python.org/mailman/listinfo/python-list


Thoughts on using isinstance

2007-01-24 Thread abcd
In my code I am debating whether or not to validate the types of data
being passed to my functions.  For example

def sayHello(self, name):
if not name:
rasie "name can't be null"
if not isinstance(name, str):
raise "name must be a string"
print "Hello " + name

Is the use of isinstance a "bad" way of doing things?  is it a "heavy"
operation?  for example, if I use this in each function validate input
will it slow things down a lot?

just curious how you might handle this type of situation (other than
not validating at all).

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Search Queue

2007-01-16 Thread abcd
Yea basically I need Queue like functionality with the ability to
search for a particular instance in it.  I guess I could just use a
list and search it as needed.

Thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Search Queue

2007-01-16 Thread abcd
I have a class such as...

id = 0
class Foo:
def __init__(self, data):
self.id = id
id += 1
self.data = data

And I am storing them in a Queue.Queue...

import Queue
q = Queue.Queue()
q.put(Foo('blah'))
q.put(Foo('hello world'))
q.put(Foo('test'))

how can I search "q" for an instance of Foo which has 'id' equal to say
2?  Typically a queue only lets you put and get, not really search.

Thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determine an object is a subclass of another

2007-01-09 Thread abcd
yea i meant to have animal extend thing and dog extend animalmy
mistake.

anyways, is there a way to check without having an instance of the
class?

such as,

isinstance(Dog, (Animal, Thing)) ??

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Determine an object is a subclass of another

2007-01-09 Thread abcd
How can tell if an object is a subclass of something else?

Imagine...

class Thing:
pass

class Animal:
pass

class Dog:
pass

d = Dog()

I want to find out that 'd' is a Dog, Animal and Thing.  Such as...

d is a Dog
d is a Animal
d is a Thing

Thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


More Efficient fnmatch.fnmatch for multiple patterns?

2007-01-08 Thread abcd
I am using fnmatch.fnmatch to find some files.  The only problem I have
is that it only takes one pattern...so if I want to search using
multiple patterns I have to do something like

patterns = ['abc*.txt', 'foo*']

for p in patterns:
if fnmatch.fnmatch(some_file_name, p):
return True

...is there a built-in function that will match using multiple patterns?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython TextCtrl - weird scrolling behavior

2006-11-01 Thread abcd
thanks for the feedback, I am watching the screencasts, which are
helping already.  I think I will try out the Dabo GUI tool since it
uses wxPython...and see if I can get the code I need from it.

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python windows interactive.

2006-10-30 Thread abcd
> How do I do sometihing simple like that in python?

print "hello"
print "Jim"

> How do I enter line numbers, or if none, what do I do.

no line numbers needed

> Can the interpreter load a text file with my program in it?

read in a text file:
data = open("something.txt").read()

> How do I list a program or the parts of a program I am interested in
> looking at?

say you want to know what you can do with a list
x = [1,2,3,4,5]

dir(x)
help(x)
help(x.append)

>
> How do I run a python program?

create a file, type some code.  then to at the end of the file (put
this)...

if __name__ == "__main__":
# call your functions here

this will let you run it from command line like this:
c:> python foo.py

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython TextCtrl - weird scrolling behavior

2006-10-30 Thread abcd
On Oct 30, 3:47 pm, John Salerno <[EMAIL PROTECTED]> wrote:
>I noticed that one object you refer to is
> self.textPane, is that supposed to be self.textPanel?

no, self.textPane is the actual wx.TextCtrl.

I used a GUI Builder to the layout stuff...perhaps that's my problem :)

is there a good site to refer to for how to use sizers?  i am
essentially creating a chat window (textPane is the history of the
chat, then a textCtrl below it for typing a new message and a button
next to the input field and buttons below the input field).

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython TextCtrl - weird scrolling behavior

2006-10-30 Thread abcd
> But one question that comes to mind is, do you not add sizerTextPanel to
> sizerMainPanel? I think all sub-sizers should be added to the main
> sizer, unless there's some weird reason I don't know of.

well i set the sizer on the textPanel and then I add the textPanel to
sizerMainPanel

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython TextCtrl - weird scrolling behavior

2006-10-30 Thread abcd
On Oct 30, 2:52 pm, John Salerno <[EMAIL PROTECTED]> wrote:
Don't know for sure, but you can try calling the Refresh() method on
the
> text control and see if that fixes it.

Didn't make a difference.  Not sure what the problem is, I am wondering
if it is a layout issue since that is my weak spot with wxPython.

sizerTextPanel =
wx.StaticBoxSizer(self.sizerTextPanel_staticbox, wx.HORIZONTAL)
sizerTextPanel .Add(self.textPane, 1, wx.ALL|wx.EXPAND, 2)
self.textPanel.SetAutoLayout(True)
self.textPanel.SetSizer(sizerTextPanel )
sizerTextPanel .Fit(self.textPanel)
sizerTextPanel .SetSizeHints(self.textPanel)
sizerMainPanel.Add(self.textPanel, 3, wx.ALL|wx.EXPAND, 0)


not sure if that means anything to anyone :)

-- 
http://mail.python.org/mailman/listinfo/python-list


wxPython TextCtrl - weird scrolling behavior

2006-10-30 Thread abcd
I have a TextCtrl which is set to be multi-line.  I have a function
say, updateText(msg), which takes some string and appends it to the
text control...

txtControl.AppendText(msg)

however, if the text that I am appending would cause the scroll
bars to appear/or scroll since the text is long the textcontrol appears
to be blank, until you click on the scroll bar...then the text appears.
 Any ideas?  is this is a sizer problem or a TextCtrl issue??

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Image.draft -- what are the modes that I can use?

2006-10-19 Thread abcd
Gabriel Genellina wrote:
> A VNC server is about 400K in size...


Yea, VNC is not an option in my case.

thanks anyway, perhaps I'll look into generating a slideshow using
HTML/javascript which can load the images.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Image.draft -- what are the modes that I can use?

2006-10-18 Thread abcd
Brett Hoerner wrote:
> Are you sure you can't use VNC?  An animated GIF based on full-screen
> grabs will be amazingly huge and have very low color quality at the
> same time.
>
> Installing VNC on Windows should take you about 30 seconds, honest.
>
> Or is this for some sort of project where you can't use anything but
> CPython software...?
> 
> Brett Hoerner


the latter.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Image.draft -- what are the modes that I can use?

2006-10-18 Thread abcd
fredrik,
   in other posts you have mentioned the use of gifmaker.  i have tried
that with the following:

I am using gifmaker.py from PIL v1.1.5 on python 2.4.1.

CODE

import ImageGrab, gifmaker

seq = []

while keepOnGoing:
im = ImageGrab.grab()
seq.append(im)

fp = open("out.gif", "wb")
gifmaker.makedelta(fp, seq)
fp.close()

---

however I am getting this error:

Exception in thread Thread-3:
Traceback (most recent call last):
  File "c:\Python24\lib\threading.py", line 442, in __bootstrap
self.run()
  File "c:\foo.py", line 10, in run
gifmaker.makedelta(fp, seq)
  File "c:\gifmaker.py", line 79, in makedelta
for s in getheader(im) + getdata(im):
  File "c:\Python24\Lib\site-packages\PIL\GifImagePlugin.py", line 383,
in getdata
ImageFile._save(im, fp, [("gif", (0,0)+im.size, 0,
RAWMODE[im.mode])])
KeyError: 'RGB'

Any ideas?  Basically I want to make an animated GIF out of a bunch of
images taken using the ImageGrab module.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Image.draft -- what are the modes that I can use?

2006-10-18 Thread abcd
Fredrik Lundh wrote:
> to repeat myself:
>
> here's a tool that lets you use VNC to capture the screen, and then 
> convert
> the result to a flash animation:
>
>http://www.unixuser.org/~euske/vnc2swf/
>
> 

is there a way to make animated GIFs with python?  vnc2swf is to much
for what i was hoping.  i have no problem with installing python
packages, but having to use VNC is a bit much.

thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Image.draft -- what are the modes that I can use?

2006-10-18 Thread abcd
oh and vnc2swf would not be an option, i cant be setting up a vnc
server, etc.  just need to use python (and necessary packages).

animated gif would probably be best i am assuming.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Image.draft -- what are the modes that I can use?

2006-10-18 Thread abcd
Fredrik Lundh wrote:
> GIF is horribly unsuitable for screenshots on modern machines.  have you
> considered using PNG ?
>
> or even better, Flash?

well I am trying to take screenshots and make them into an animated
GIF, however, putting them into a Flash movie would be coolany idea
how to go about doing either with python?  (windows, possibly linux
later)

-- 
http://mail.python.org/mailman/listinfo/python-list


PIL: Image.draft -- what are the modes that I can use?

2006-10-18 Thread abcd
I have PIL 1.1.5 on python 2.4.1 and I am attempting to get a smaller
(file size) of an image.

for example:
im = ImageGrab.grab()

im.save("tmp.gif") about 1.7mb
im.save("tmp.jpeg")   about 290kb

anyways I want to save the image as a GIF, but not have it be so
largeso I thought that the Image.draft method would be what I
wanted

im.draft(mode, size)

Configures the image file loader so it returns a version of the image
that as closely as possible matches the given mode and size. For
example, you can use this method to convert a colour JPEG to greyscale
while loading it, or to extract a 128x192 version from a PCD file.

.what 'modes' can I use?  or is there another way to shrink the
size of the image (other than resizing it)?

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Problem creating animated gif

2006-10-17 Thread abcd
I am using gifmaker.py from PIL v1.1.5 on python 2.4.1.

CODE

import ImageGrab, gifmaker

seq = []

while keepOnGoing:
im = ImageGrab.grab()
seq.append(im)

fp = open("out.gif", "wb")
gifmaker.makedelta(fp, seq)
fp.close()

---

however I am getting this error:

Exception in thread Thread-3:
Traceback (most recent call last):
  File "c:\Python24\lib\threading.py", line 442, in __bootstrap
self.run()
  File "c:\foo.py", line 10, in run
gifmaker.makedelta(fp, seq)
  File "c:\gifmaker.py", line 79, in makedelta
for s in getheader(im) + getdata(im):
  File "c:\Python24\Lib\site-packages\PIL\GifImagePlugin.py", line 383,
in getdata
ImageFile._save(im, fp, [("gif", (0,0)+im.size, 0,
RAWMODE[im.mode])])
KeyError: 'RGB'


Any ideas?  Basically I want to make an animated GIF out of a bunch of
images taken using the ImageGrab module.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tertiary Operation

2006-10-17 Thread abcd
Carsten Haese wrote:
> Use Python 2.5 where there is a true conditional
> expression or find another way to solve your problem.

python 2.5 once we upgrade (hopefully soon), anyways...an earlier post
suggested the inverse...

x = None
result = (x is not None and str(x) or "")

which works just fine.

thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Tertiary Operation

2006-10-17 Thread abcd
x = None
result = (x is None and "" or str(x))

print result, type(result)

---
OUTPUT
---
None 


y = 5
result = (y is 5 and "it's five" or "it's not five")

print result

-
OUTPUT
-
it's five

...what's wrong with the first operation I did with x?  I was expecting
"result" to be an empty string, not the str value of None.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strange Behavior

2006-10-16 Thread abcd
Rob Williscroft wrote:
> http://docs.python.org/ref/function.html#l2h-619


thanks.  weird that it works that way since they even state "This is
generally not what was intended."

oh well.

-- 
http://mail.python.org/mailman/listinfo/python-list


Strange Behavior

2006-10-16 Thread abcd
class Foo:
def __init__(self, name, data=[]):
self.name = name
self.data = data

def addData(self, val):
self.data.append(val)


f = Foo('a')
f.addData(1)
f.addData(2)

f2 = Foo('b')

print f.name, f.data
print f2.name, f2.data


OUTPUT
---
a [1, 2]
b [1, 2]


why would f and f2 contain the same data??

however, if I do this instead

f = Foo('a')
f.addData(1)
f.addData(2)

f2 = Foo('b', [])

print f.name, f.data
print f2.name, f2.data


OUTPUT
---
a [1, 2]
b []


Any ideas?  is this a bug?

-- 
http://mail.python.org/mailman/listinfo/python-list


Extend file type

2006-09-26 Thread abcd
I have a class which extends 'file' 

class MyFile(file):
def __init__(self, fname, mode='r'):
file.__init__(self, fname, mode)

def write(self, str):
print "writing a string"
file.write(self, str)

def writelines(self, lines):
print "writing lines"
file.writelines(self, lines)

I use this with subprocess

f = MyFile('out.txt', 'w')
p = subprocess.Popen(cmd, stdout=f)

and I can see that stuff goes into out.txt.however, I never see
"writing a string" or "writing lines" from the class MyFile.

Any ideas what methods the stdout (and I guess stderr) of Popen objects
from subprocess call?

Any suggestions on how to find out?  I did try adding to MyFile

def __call__(self, *args):
print "calling:", args
return file.__call__(self, *args)


but I never see that either.

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxTimer problem

2006-09-15 Thread abcd
> Fix: Start the script from the main thread only.
>
> Regards,
>
>
> Björn


thanks for NO help.anyways, I got rid of the Timer b/c all i was
using it for was to check the state of the "shift" key.but I am now
binding to key up/down.

thanks anyway

-- 
http://mail.python.org/mailman/listinfo/python-list


wxTimer problem

2006-09-15 Thread abcd
I have a python script which creates a wx.App, which creates a wx.Frame
(which has a wx.Timer).

looks sorta like this:

class MyProgram:
def __init__(self):
self.app = MyApp(0)
self.app.MainLoop()

class MyApp(wx.App):
def OnInit(self):
self.myframe= MyFrame()
self.myframe.Show(True)
self.SetTopWindow(self.myframe)
return True

class MyFrame(wx.Frame):
def __init__(self):
   # do some other stuff here

   # setup the timer
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)
self.timer.Start(100)

def killTimer(self):
self.Unbind(wx.EVT_TIMER)
self.timer.Stop()
self.timer = None


that's the jist of it.

Anyhow, so I startup python and import my script, which loads up the
wx.App, frame and all.

foo = MyProgram()


Then I close the frame.  when the frame is closed it calls killTimer.
This method gets called and no exceptions occur.

Then...I create a new instance of the app and try to load the frame
again.

foo = MyProgram()

...and I am getting this error:

"timer can only be started from the main thread"

how can I fix this??

FYI, my script is being started by a new thread each time, so
ultimately we have

def startProgram():
foo = MyProgram()

threading.Thread(target=startProgram).start()


Thanks in advance.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: block a network port

2006-08-29 Thread abcd
Larry Bates wrote:
> This is not really a Python question.  Blocking ports is a function
> of your firewall solution.
> 


ok, no of any python solutions?  or command-line firewalls?

-- 
http://mail.python.org/mailman/listinfo/python-list


block a network port

2006-08-29 Thread abcd
any ideas on how to block a network port from being used, or one that
is currently in use?  For example, say I want to block port 23 from
being used.  by used, I mean allowing connections to or from it.

thanks in advance.

-- 
http://mail.python.org/mailman/listinfo/python-list


format a number for output

2006-08-07 Thread abcd
if i have a number, say the size of a file, is there an easy way to
output it so that it includes commas?

for example:

1890284

would be:

1,890,284

I am looking for something builtin to python, not a third party lib.

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


regex for replacing \r\n

2006-08-07 Thread abcd
I am trying to get a regex that will match \r\n in a string.
ultimately i am trying to replace all \r\n with somethign else, say
BLAH.

For example:
This is a message
on a new line

would become:
This is a messageBLAHon a new line.

any ideas?  i tried

re.compile('\r\n').match("This is a message" + os.linesep + "on a new
line") but no match.  And I am on windows, so os.linesep gives
'\r\n'

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with regex

2006-07-28 Thread abcd
not sure why this passes:


>>> regex = r'[A-Za-z]:\\([^/:\*\?"<>\|])*'
>>> p = re.compile(regex)
>>> p.match('c:\\test')
<_sre.SRE_Match object at 0x009D77E0>
>>> p.match('c:\\test?:/')
<_sre.SRE_Match object at 0x009D7720>
>>>

the last example shouldnt give a match

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with regex

2006-07-28 Thread abcd
Sybren Stuvel wrote:
> Yes, because after the "c:" you expect a backslash, and not a tab
> character. Read the manual again about raw strings and character
> escaping, it'll do you good.


doh.  i shall do that.

thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with regex

2006-07-28 Thread abcd
sorry i forgot to escape the question mark...

> [code]
> import re
> p = re.compile(r'[A-Za-z]:\\([^/:\*?"<>\|])*')

even when I escape that it still doesnt work as expected.

p = re.compile(r'[A-Za-z]:\\([^/:\*\?"<>\|])*')

p.match('c:\test')  still returns None.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with regex

2006-07-28 Thread abcd
well thanks for the quick replies, but now my regex doesn't work.

[code]
import re
p = re.compile(r'[A-Za-z]:\\([^/:\*?"<>\|])*')

x = p.match("c:\test")
[/code]

x is None

any ideas why?  i escape the back-slash, the asterisk *, and the PIPE |
b/c they are regex special characters.

-- 
http://mail.python.org/mailman/listinfo/python-list


problem with regex

2006-07-28 Thread abcd
I have a regex: '[A-Za-z]:\\([^/:\*\?"<>\|])*'

when I do, re.compile('[A-Za-z]:\\([^/:\*\?"<>\|])*') ...I get

sre_constants.error: unbalanced parenthesis

do i need to escape something else?  i see that i have matching
parenthesis.

thx

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: regular expression - matches

2006-07-21 Thread abcd
yea i saw thatguess I was trusting that my regex was accurate :)
...b/c i was getting a Matcher when I shouldnt have, but i found that
it must be the regex.

-- 
http://mail.python.org/mailman/listinfo/python-list


regular expression - matches

2006-07-21 Thread abcd
how can i determine if a given character sequence matches my regex,
completely?

in java for example I can do,
Pattern.compile(regex).matcher(input).matches()

this returns True/False whether or not input matches the regex
completely.

is there a matches in python?

-- 
http://mail.python.org/mailman/listinfo/python-list


Network Ports - blocking / taking over

2006-06-12 Thread abcd
Just curious if anyone had any information, or links, regarding the
blocking of network ports and/or taking over (hijacking) ports using
Python.

Any python modules/libs you could recommend?  tutorials/reading
materials?

Thanks in advance.

-- 
http://mail.python.org/mailman/listinfo/python-list


Importing again and again

2006-06-08 Thread abcd
If I have code which imports a module over and over again...say each
time a function is called, does that cause Python to actually re-import
it...or will it skip it once the module has been imported??

for example:

def foo():
import bar
bar.printStuff()

foo()
foo()
foo()
foo()

...will that re-import bar 4 times...or just import it once?  is this a
big performance hit?

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PythonDoc Ant Task

2006-06-01 Thread abcd
i found that the problem is because of an import, which is strange.
The imported module looks something like this

[code]
import time

class Foo:
pass

class Bar:
global javax.swing
import javax.swing
[/code]

so it seems that pydoc cant giggity-giggit!

-- 
http://mail.python.org/mailman/listinfo/python-list


PythonDoc Ant Task

2006-06-01 Thread abcd
Anyone ever use the PythonDoc ant task?  I have the following...















...this is a cut out of the build xml i am using...but it shows the
relevant parts.  Anyways I can run my "pyDoc" target and it runs
successful with no errors.  a "docs" directory is created but is empty.
 Any idea as to why?

My "src" folder contains a python file, Foo.py.  which looks like this

class Bar:
def printMe(self):
"""This method prints my data"""
print "some data is being printed"

...Thanks in advance.

-- 
http://mail.python.org/mailman/listinfo/python-list


Add file to zip, or replace file in zip

2006-04-28 Thread abcd
I have a script which zips up a directory, once it does with that
(before it closes the zip file) I want to replace a file that was added
to the zip, say "Foo.txt".

So I tried this...
[code]
z = zipfile.ZipFile("blah.zip", "w")
# zip the directory
#...
z.writestr("c:\\path\\to\\current\\foo_txt_file\\Foo.txt", "some new
data")
z.close()

All this does is add a new Foo.txt file in the zip alongside the
existing oneany suggestions?

Thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Jython: exec a string

2006-04-21 Thread abcd
the error i get when i run the exec is, "java.lang.ClassFormatError"...

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Jython: exec a string

2006-04-21 Thread abcd
I have a single jython file, foo.py which contains multiple classes.  I
read that into a string and try to exec itbut I get errors saying
something like unable to load class.  It seems to work fine if foo.py
only contains a single class, any ideas?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to determine an object is "scriptable"

2006-03-30 Thread abcd
Daniel Evers wrote:
> Right. You can check this e.g. with
>
> hasattr(x, "__getitem__")
>
> because the __getitem__ method is used for indexing.

Thanks...that is what I was looking for!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to determine an object is "scriptable"

2006-03-30 Thread abcd
Richard Brodie wrote:
> subscriptable: supports an indexing operator, like a list does.

doesn't seem to be a builtin function or module...or is that just your
definition of subscriptable?

-- 
http://mail.python.org/mailman/listinfo/python-list


How to determine an object is "scriptable"

2006-03-30 Thread abcd
I recently came across a problem where I saw this error:
"TypeError: unsubscriptable object"

How can I determine if an object is "scriptable" or "unscriptable"?

-- 
http://mail.python.org/mailman/listinfo/python-list


Redirect output

2006-03-28 Thread abcd
I have a program which is written in C and interfaced with python via
Swig.  However, the function I call prints stuff out to the console.  I
would like to capture what it is printing out.  I tried:

[code]
import MyCProg, sys

f = open("tmp.txt", "wb")
sys.stdout = f
MyCProg.getData()
f.close()
sys.stdout = sys.__stdout__

print open("tmp.txt", "rb").read()
[/code]

However, it just prints the data to the screen.  I tried redirecting
stderr as well.

other than modifying the C code and re-generating the interface via
Swig, any ideas?  just asking before i have to do that.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pysqlite

2006-03-27 Thread abcd
Dennis Lee Bieber wrote:
> On 27 Mar 2006 10:17:21 -0800, "abcd" <[EMAIL PROTECTED]> declaimed
> the following in comp.lang.python:
>
> > anyone have v2.x of pysqlite that I could download?  the website is
> > down for a hardware upgrade with no date as to when it will be back.
> >
>   Source or binary (or everything)? Architecture?

I need v 2.x for windows, running python v2.4

u can email it to me, codecraig _A_T_ gmail _D_O_T_ com

thx

-- 
http://mail.python.org/mailman/listinfo/python-list


pysqlite

2006-03-27 Thread abcd
anyone have v2.x of pysqlite that I could download?  the website is
down for a hardware upgrade with no date as to when it will be back.

I checked sourceforge but there are no files there to download.

thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


pythoncom.PumpMessages - how to quit

2006-03-09 Thread abcd
When I call:

pythoncom.PumpMessages()

...it blocks at that line.  According to the docs, it says it will run
until it receives a WM_QUITso I try to create a separate thread and
do

import win32api
win32api.PostQuitMessage()

...but the code is still blocking at PumpMessages.  Any ideas?  other
than killing python?

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


pythoncom.PumpMessages - how to quit

2006-03-09 Thread abcd
When I call:

pythoncom.PumpMessages()

...it blocks at that line.  According to the docs, it says it will run
until it receives a WM_QUITso I try to create a separate thread and
do

import win32api
win32api.PostQuitMessage()

...but the code is still blocking at PumpMessages.  Any ideas?  other
than killing python?

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyCon2006 - will the content be available for download?

2006-03-08 Thread abcd
well actually, the site looked promising...only problem is no talks
have audio, video or handouts available (at least right now).

oh well.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyCon2006 - will the content be available for download?

2006-03-08 Thread abcd
Max M wrote:
> http://us.pycon.org/AudioVideoRecording/HomePage

Thanks, after going to the URL, I clicked "talks" and got to
http://us.pycon.org/talks  ...this page lets u pick which talks you
want to access.

thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


PyCon2006 - will the content be available for download?

2006-03-08 Thread abcd
Anyone know if (and when) the talks from PyCon2006 will be available
for download.  I am particularly interested in the tutorials (as they
did not have them at PyCono2005).

Thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: error: argument after ** must be a dictionary

2006-03-01 Thread abcd
i was missing "self" in my method signature!

doh!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: error: argument after ** must be a dictionary

2006-03-01 Thread abcd
Not sure if it matters, but this occurs when running a unittest.

The trace back is:
Traceback (most recent call last):
  File "C:\Python24\Lib\threading.py", line 442, in __bootstrap
self.run()
  File "C:\Python24\Lib\threading.py", line 422, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: MyTestCase object argument after ** must be a dictionary

Unhandled exception in thread started by >

-- 
http://mail.python.org/mailman/listinfo/python-list


error: argument after ** must be a dictionary

2006-02-28 Thread abcd
I have class like this...

import threading
class MyBlah(object):
def __init__(self):
self.makeThread(self.blah, (4,9))

def blah(self, x, y):
print "X and Y:", x, y

def makeThread(self, func, args=(), kwargs={}):
threading.Thread(target=self.blah, args=args,
kwargs=kwargs).start()

When I do...
b = MyBlah()

I am getting this error:
TypeError:  MyBlah object argument after ** must be a dictionary

What am I missing?

-- 
http://mail.python.org/mailman/listinfo/python-list


Format file size for printing

2006-02-19 Thread abcd
is there a built-in way of printing the size of a file nicely?

So if the file size is 103803 bytes it prints out like: 103.8K
or
0.1MB 

something liek that?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Get parameters from URL using CGI

2006-02-18 Thread abcd
Ian Leitch wrote:
> >>> from urlparse import urlparse
> >>> dict([n for n in [i.split('=') for i in
> urlparse('http://www.somesite.com/cgi-bin/foo.cgi?name=john&age=90')[4].split('&')]])
> {'age': '90', 'name': 'john'}


Ian,  thanks for the reply, but that is not what I need to do.  Inside
foo.cgi how can I parse out the values given in the URL?

So if you visit: http://www.somesite.com/cgi-bin/foo.cgi?valA=1&valB=2
.I want the script, foo.cgi to print out the parameters and their
values.  It's dynamic so the values are url wont be the same all the
time.  How do i get the URL from the script?  does this make sense?

So I'm thinking foo.cgi will look like
[code]
url = getTheFullURL()
parse(url)

def parse(url):
# parse the parameter names and values
[/code]

-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >