Iterate through a list and try log in to a website with urllib and re

2014-03-03 Thread Marcus
Hello,

I'm trying to use urllib and urllib2 to open an url + login_data in a for loop. 
How can I display when successfully logged in and how to show when the login is 
denied? 

I've tried use this:

html_content = urllib2.urlopen(url).read()
re.findall('ERROR: The password you entered for the username USER is 
incorrect.', html_content)

1. I want to try an if statement in a for loop
2. Iterate through a list and when the first password in the list is denied. It 
shall continue with the next password in the list and try that one.
3. When it's successfully logged in the program will stop the loop and print 
out the password that matches.

I'm stuck and need some help creating this.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Iterate through a list and try log in to a website with urllib and re

2014-03-03 Thread Marcus
This is the code right now: http://pastebin.com/pE1YZX2K
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Iterate through a list and try log in to a website with urllib and re

2014-03-03 Thread Marcus
Yes, it's only for my own use on my local WordPress installation. Only 
educational use. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Iterate through a list and try log in to a website with urllib and re

2014-03-03 Thread Marcus
It's not that hard to find a program that does this already. But I'm trying to 
learn how to use these modules to create this. I've started it and now i want 
to complete it so I can create another program and learn more about other 
stuff, maybe a Twitter script or something. How do I learn when not practice? 
-- 
https://mail.python.org/mailman/listinfo/python-list


moinmoin advocacy?

2006-12-12 Thread Marcus
Apologies if this seems like it's off-topic, but since moinmoin is
written in Python, I am hoping to solicit some good thoughts in this
group.

The problem: I'm setting up a wiki farm (small software company, my
personal use as a PIM, hobby site).  I may also deploy (customized)
wikis to small/medium companies.  I've been researching wikis recently,
and I really like three: Moinmoin, Mediawiki, and SocialText (well,
Trac, too, but ...).  Moinmoin seems like a great match for me b.c. of
the python underpinnings, but I'm worried that it is a dead or dying
project, i.e.

http://www.google.com/trends?q=TWiki%2C+MoinMoin%2C+PmWiki%2C+MediaWiki%2C+DokuWiki&ctab=0&geo=all&date=all)

I'm also concerned b.c. the documentation and features seem sparse, and
I read stray comments about "lack of scalability."  Moinmoin also seems
to lag (or plainly lack) some of the more popular "hot" wiki features
found in other packages.  Finally, I've read rave reviews of the latter
two platforms, but I don't see much press (esp. positive) for Moinmoin.

Should I invest the time in Moinmoin, and development for it, or use
another platform?  Will Moinmoin be able to keep up with the heated
evolution of wikis for corporate and PIM usage?  Is there a sense of
moinmoin momentum (developer or user)?  Is the lack of moinmoin
advocacy a consequence of a weak product, or something else?

Thanks,
Marcus

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


Third-party libs in version control

2007-06-09 Thread Marcus
Good evening,

I'm new to developing large subversion-controlled projects. This one
will involve a few third-party libraries like wxWidgets, and perhaps
Twisted. Ordinarily you could just install these into your system and
they'll end up globally (in Python's Lib/site-packages directory). Is it
proper practice to instead install the libraries into a separate [vendor
branch] of the repository and reference that instead?

I've read about vendor branches, and I'm under the impression that
you're supposed to do that /instead/ of installing the libraries
globally into Python's subdirectories... is that correct?

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


Re: error return without exception set

2007-07-03 Thread Marcus
Will McGugan wrote:
> Thanks for the explanation. It happens when I'm debugging a wxWidgets
> application with Komodo, but I can't trap it. I'm guessing it must be a
> Komodo issue, because I dont get it if I run it without the debugger.

The error happens in PyDev for Eclipse also -- only while debugging.

It happens with or without wxWidgets; I've always assumed it's a pydev
issue.
-- 
http://mail.python.org/mailman/listinfo/python-list


Using eggs or py2exe to distribute apps

2007-07-19 Thread Marcus
Hi,

I'm to the stage where I need to deploy the app I built with wxPython. 
I've been able to successfully build it w/py2exe into a binary (about 
10MB size in total).

What I'd like to do is create an automatic updater, so that I can have 
users download updated versions of my *application code* without having 
to have them redownload everything (the interpreter, etc) via a complete 
redownload (I want to package some things as "components").

Eggs seem like an ideal solution, but I haven't had any luck using them 
in conjunction with py2exe.

It would seem that the most effective solution would be to package a 
python interpreter (with wxPython, etc already included) into the 
distributed app's directory and not use py2exe at all; however, since 
everything would be included in the distribution, it would seem that the 
full python distro would be huge (50MB at least), which defeats the 
purpose of wanting to build the app into "components".

Worst-case scenario would be to have them redownload the 10MB update 
each time, but that's less than ideal, since the audience for my program 
would have more frequent/less substantial updates over time, rather than 
big updates all at once.

Any guidance or suggestions are very much appreciated.

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


calendar (date) iterator?

2007-03-06 Thread Marcus
Hi,

I'm looking for useful starting points, suggestions, and sample code,
to implement a calendar iterator.  Simply, the iterator is seeded with
an initial calendar date, e.g., "03-12-2006", and then subsequent
calls to next return subsequent dates.  The seed could be a standard
calendar/datetime object.

> iter = calendarIterator("03-12-2006")
> print iter.next()

   03-12-2006

A useful extension would be to allow specifiation of iter intervals,
e.g.,

> iter = calendarIterator("03-12-2006 01:00:00", "minutes")
> print iter.next()

   03-12-2006 01:01:00

Thanks in advance for pointers and suggestions!

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


Re: calendar (date) iterator?

2007-03-06 Thread Marcus
Oops-- the iter needs to work better than I do! :)

> > iter = calendarIterator("03-12-2006")
> > print iter.next()
>
>03-12-2006
 ^^
 03-13-2006


> > iter = calendarIterator("03-12-2006 01:00:00", "minutes")
> > print iter.next()
>
>03-12-2006 01:01:00
 ^^
 03-13-2006

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


Re: calendar (date) iterator?

2007-03-06 Thread Marcus
On Mar 6, 3:19 pm, [EMAIL PROTECTED] wrote:
>     Marcus> I'm looking for useful starting points, suggestions, and sample
> Marcus> code, to implement a calendar iterator.
>
> Have you looked at dateutil?
>
>http://labix.org/python-dateutil
>
> >>> from dateutil.rrule import rrule, DAILY
> >>> from dateutil.parser import parse
> >>> rule = rrule(DAILY, count=5, dtstart=parse("2006-03-12"))
> >>> for d in rule:
> ...   print d
> ...
> 2006-03-12 00:00:00
> 2006-03-13 00:00:00
> 2006-03-14 00:00:00
> 2006-03-15 00:00:00
> 2006-03-16 00:00:00
>
> Skip


This is exactly what I was looking for!  Thanks so much!!

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


Re: Looping Problem (Generating files - only the last record generates a file)

2005-10-26 Thread Marcus Ekelund
[EMAIL PROTECTED] wrote:
> Hello All,
>
> I have a problem with the program that should generate x number of txt
> files (x is the number of records in the file datafile.txt).
>
> Once I execute the program (see below) only one file (instead of x
> files) is created. The file created is based on the last record in
> datafile.txt.
>
> The program is as follows:
> 
> #!  python
>
> HEADER = "This page displays longitude-latitude information"
> SUBHEADER = "City"
>
> for line in open("datafile.txt"):
>
>
> town, latlong = line.split('\t')
>
> f = open(town + ".txt", "w+")
>
> f.write(HEADER + "\n")
> f.write(SUBHEADER + ": " + town + "\n")
> f.write("LAT/LONG" + ": " + latlong + "\n")
> f.close()
>
>
> # end
> 
>
>
>
>
> The datafile.txt is as follows (tab separated columns):
> 
>
> NYC   -
> Lima  -
> Rome  -
>
> 
>
> Once executed, the program will create a single file (named Rome.txt)
> and it would not create files NYC.txt and Lima.txt as I would expect it
> to do.
>
> I'd appreciate if you can pinpoint my error.

Since the lines that handle writing to the file aren't indented as far
as the line that splits the data, they are not part of the loop. They
are only executed  once after the loop has completed, with town and
latlong set to the values they got at the last iteration of the loop.

It should look more like this:

for line in open("datafile.txt"):
town, latlong = line.split('\t')

f = open(town + ".txt", "w+")
f.write(HEADER + "\n")
f.write(SUBHEADER + ": " + town + "\n")
f.write("LAT/LONG" + ": " + latlong + "\n")
f.close()

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


Do I need to have site.py available or not ?

2005-08-05 Thread marcus . obrien
Hi,
on startup my embedded python comes up with "import site failed use
-v". Later python crashes on Pyrun_file(). This is the first time I
have used python and I would like to know does it require site.py to be
read in, and has anyone got an idea how to pass in the -v without using
the python -v command, ie the embedded way. Thanks very much.

Marcus.

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


Cpickle module... not in Lib installs

2005-03-25 Thread Marcus Lowland
Hello, I'm fairly new to python and have read about and wanted to begin
experimenting with cpickle. As I understand, this should be a native
module in the python library. I have python 2.3 and now just installed
2.4, but am not able to import or find cpickle.py in any directory of
the install, or in the previous version (pickle.py is present and
imports correctly). Is there a seperate module package that must be
downloaded and installed... or am I overlooking the obvious.

Would appreciate any suggestions on how to acquire/load the module.

Regards,
Marcus

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


Re: Cpickle module... not in Lib installs

2005-03-25 Thread Marcus Lowland
Thanks Marc, but... I've searched the file directories for cpickle (not
specifying file type) and only came up with test_cpickle.py. Also, if
cPickle.so were the correct file and existed in my lib then the
following would not happen.

>>> import cpickle

Traceback (most recent call last):
  File "", line 1, in -toplevel-
import cpickle
ImportError: No module named cpickle
>>>

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


Re: Cpickle module... not in Lib installs

2005-03-25 Thread Marcus Lowland
Arrghh, I forgot about case sensitivities sorry about that
guys, I'm so used to not having to think about that. Thanks for having
patience with me and thanks for the explanations.

import cPickle

hehe... damn... tricky getting used to that :-)

Thanks again,
Marcus

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


Re: Finding attributes in a list

2005-04-02 Thread Marcus Goldfish
> class Player(object):
>def __init__(self, **kw): self.__dict__.update(kw)
>def __repr__(self): return ''%getattr(self, 'name', 
> '(anonymous)')
>
> import operator
> [p.name for p in sorted(players, key=operator.attrgetter('attacking'), 
> reverse=True)]

Just happened to read this thread and wanted to say this is a neat
little example-- thank you!  I have a couple of followup questions.

   (1) Is there a performance penalty for using key=operator.attrgetter()?
   (2) The Player class looks like a nice model for a data table when one
wants to sort by arbitrary column.  Would you agree?
   (3) Suppose one wished to construct a player list from a collection of
attribute lists, e.g.,

names = ['bob', 'sam', 'linda']
attack = [7, 5, 8]
defense = [6, 8, 6]
# construct players list here

   Can you recommend an efficient way to construct the player list?

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


pythonic use of properties?

2005-04-14 Thread Marcus Goldfish
I'd like advice/opinions on when it is appropriate to do
attribute/property validation in python.  I'm coming from a C#/Java
background, where of course tons of "wasted" code is devoted to
property validation.  Here is a toy example illustrating my question:

#   Example: mixing instance attributes with properties.  Is it pythonic to
#   validate property data in setters?  Since tens and ones are never
#   validated, the class can be "broken" by setting these directly
class SillyDecimal(object):
   """A silly class to represent an integer from 0 - 99."""
   def __init__(self, arg=17):
   if isinstance(arg, tuple):
   self.tens = arg[0]
   self.ones = arg[1]
   else:
   self.number = arg

   def getNumber(self):
   return self.tens*10 + self.ones
   def setNumber(self, value):
   if value < 0 or value > 99:
   raise ArgumentException("Must in [0, 99]")
   self.tens = value // 10
   self.ones = value % 10
   number = property(getNumber, setNumber, None, "Complete number, [0-99]")

x = SillyDecimal()
x.number, x.tens, x.ones# returns (17, 7, 1)

Even though "tens", "ones" and "number" all appear as attributes, only
"number" has its input validated.  Since the class is designed to only
hold numbers 0 - 99, one can 'break' it by setting self.tens=11, for
example.  Should tens and ones be made into full-fledged properties
and validated?  Should number have no validation?  Is it more pythonic
to encapsulate tightly, or rely on "responsible use."

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


Re: pythonic use of properties?

2005-04-15 Thread Marcus Goldfish
On 4/15/05, Michael Spencer <[EMAIL PROTECTED]> wrote:
> > class SillyDecimal(object):
> >"""A silly class to represent an integer from 0 - 99."""
> >def __init__(self, arg=17):
> >if isinstance(arg, tuple):
> >self.tens = arg[0]
> >self.ones = arg[1]
> It is conventional to indicate 'private' attributes with the _ prefix.
Well, I actually want to expose tens and ones, which is why they are
not private.

> By this standard, you have three 'public' interfaces: number, get/setNumber 
> and
> ones/tens, which is confusing and error-prone.  Moreover, if you are going to
> validate number, it might make more sense to put all the validation logic into
> the setter vs. splitting some into __init__.  So your class could look like:
Of course the toy example would be better coded by changing the
internal representation to number (instead of tens and ones), but then
the point about property validation is lost, as you demonstrate in
your example.

> As for whether it is appropriate to validate the value at all, I think that
> depends on your larger design.
So what do you consider when making this decision, and do these
factors differ between python and C#/Java?

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


Re: Using python from a browser

2005-04-15 Thread Marcus Goldfish
> > I read that IE had the capability to embedd Python scripts, but what
> > about the others ?
> 
>   While Python can be set up as a scripting language for IE, this is
> normally disabled as it could be a security hole. The open call is
> available from Python scripts so a web site could read or destroy your
> files.

Slightly off-topic, it is possible to use browser helper objects
(bhos) with Internet Explorer:

http://starship.python.net/crew/theller/moin.cgi/CtypesLinks

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


Re: internet explorer/firefox plugin/toolbar

2005-04-22 Thread Marcus Goldfish
> does anyone have any ideas as to how to go about creating a plugin/toolbar
> for both/either the IE/Firefox browsers?
For IE, checkout Browser Helper Objects (BHOs).  Sample python code
can be found at:

http://aspn.activestate.com/ASPN/Mail/Message/ctypes-users/2263094

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


help with binary file io, perhaps with generators?

2005-04-23 Thread Marcus Goldfish
I need to write a "fast" file reader in python for binary files structured as:

… x[0] y[0] z[0] x[1] y[1] z[1]  …

where c[k] is the k-th element from sequence c.  As mentioned, the
file is binary -- spaces above are just for visualization.  Each
element, c[k], is a 16-bit int.  I can assume I know the number of
sequences in the file a priori.  Files are stored and processed on a
WinXP machine (in case Endian-ness matters).

I'm looking for suggestions on how to tackle this problem, and how to
design my reader class.  Or if anyone has sample code: that would be
appreciated, too.  Some questions I have to start with:

   (i) should I use generators for iterating over the file?
   (ii) how can I handle the 16-bit word aspect of the binary data?
   (iii) ultimately, the data will need to be processed in chunks of
 M-values at a time... I assume this means I need some
 form of buffered io wrapper, but I'm not sure where to start
 with this.

Thanks!
Marcus

Ps -- this seems like a general stream processing problem… if anyone
can recommend good refs (web) on stream processing
-- 
http://mail.python.org/mailman/listinfo/python-list

problems with Methods in Python 3.4.2

2014-12-18 Thread Marcus Lütolf
Hello Dears,

1)I am trying to do this:



>>> dir(_builtins_)



I am getting this:

Traceback (most recent call last):

  File "", line 1, in 

dir(_builtins_)

NameError: name '_builtins_' is not defined



2)I am trying to do this:



>>> 'TTA',_add_('GGA')



I’am getting this :

Traceback (most recent call last):

  File "", line 1, in 

'TTA',_add_('GGA')

NameError: name '_add_' is not defined



3)I am trying to do this:



>>> -3  .abs()



I’am getting this

Traceback (most recent call last):

  File "", line 1, in 

-3 .abs()

AttributeError: 'int' object has no attribute 'abs'



4) finally, after printing



>>>abs._doc_()



I am getting this (and so on) :

Traceback (most recent call last):

  File "", line 1, in 

abs._doc_()

AttributeError: 'builtin_function_or_method' object has no attribute '_doc_'

What did I do wrong ? Thanks for help, Marcus Luetolf, M.D., 90 Bondastreet,
CH-7000 Chur, Switzerland.





---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
http://www.avast.com
-- 
https://mail.python.org/mailman/listinfo/python-list


problems with Methods in Python 3.4.2

2014-12-21 Thread Marcus Lütolf
Hello Dears,

I solved the problem: There are two underscore key strokes required.
Marcus.

Hello Dears,

1)I am trying to do this:



>>> dir(_builtins_)



I am getting this:

Traceback (most recent call last):

  File "", line 1, in 

dir(_builtins_)

NameError: name '_builtins_' is not defined



2)I am trying to do this:



>>> 'TTA',_add_('GGA')



I’am getting this :

Traceback (most recent call last):

  File "", line 1, in 

'TTA',_add_('GGA')

NameError: name '_add_' is not defined



3)I am trying to do this:



>>> -3  .abs()



I’am getting this

Traceback (most recent call last):

  File "", line 1, in 

-3 .abs()

AttributeError: 'int' object has no attribute 'abs'



4) finally, after printing



>>>abs._doc_()



I am getting this (and so on) :

Traceback (most recent call last):

  File "", line 1, in 

abs._doc_()

AttributeError: 'builtin_function_or_method' object has no attribute '_doc_'

What did I do wrong ? Thanks for help, Marcus Luetolf, M.D., 90 Bondastreet,
CH-7000 Chur, Switzerland.





---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
http://www.avast.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: threads and timeout -> running a shell command / want to guard against infinite loops

2013-02-10 Thread marcus . liddle
On Tuesday, 19 August 2003 15:01:01 UTC+12, Marcus Liddle  wrote:
> 
> 
> Hi
> 
> I'm trying to get a really simple python program to
>   run a bash testing script and kill itself if its
>   been running to long (ie infinite loop)
> 
> create the thread object - test = TestThread()
> run the command - test.do_command("infloop.bash")
> if t.isAlive(): ...stop it
> 
> any good ideas?
> 
> cheers
> Marcus
> -- 
> Senior Assistant [mailto:m.lid...@cosc.canterbury.ac.nz]
> Dept. of  Computer ScienceUniversity of Canterbury
> Phone: +64 3  366-7001      ext: 7871  Office: 323
> [  http://www.cosc.canterbury.ac.nz/~marcus/index.html ]

Well you might try reroute the encryption subprocessors manually, but you'd 
have to leave the The Code Matrix in order to do that. Have you tried brushing 
you teeth and putting the cap back on? The things people for SEO huh? It would 
appear my Author ranked name appears here, so I thought my future-self would 
reply to my past self, thus applying entanglement theory, wave force particle 
acceleration to bend the fabric of the universe as we know it, blowing the 
infinite loop out of existence. -- thank you MrGoogle 
-- thank you Marcus Liddle
(no relation to Alice Liddle from the Liddle House)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newb: installing Jython on Windows XP ...

2006-11-10 Thread Marcus Bajohr
donkeyboy wrote:
> All,
> 
> I'm having issues installing Jython on Windows XP. I've looked on the
> web and this newsgroup but to no avail. Any suggestions? The shell
> listing is below:
> 
> NB I've got Cygwin installed, hence the Unix 'ls' on a Windows box
> 
> C:\>cd Jython
> 
> C:\Jython>ls
> jython_21.class
> 
> C:\Jython>ls "c:\Program Files\Java\jdk1.5.0_09\bin\java.exe"
> c:\Program Files\Java\jdk1.5.0_09\bin\java.exe
> 
> C:\Jython>"c:\Program Files\Java\jdk1.5.0_09\bin\java.exe" jython_21
> Exception in thread "main" java.lang.NoClassDefFoundError: jython_21
> 
> C:\Jython>"c:\Program Files\Java\jdk1.5.0_09\bin\java.exe" jython-21
> Exception in thread "main" java.lang.NoClassDefFoundError: jython-21
> 
> Any help would be of great use!!!
> 
Try it from cmd, not from the cygwin shell.
The environments differ !

greets
Marcus

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


Re: probably a stupid question: MatLab equivalent of "diff" ?

2006-12-29 Thread Marcus Goldfish

On 12/29/06, Stef Mientki <[EMAIL PROTECTED]> wrote:


Does anyone know the equivalent of the MatLab "diff" function.
The "diff" functions calculates the difference between 2 succeeding
elements of an array.
I need to detect (fast) the falling edge of a binary signal.

There's derivate function in Python diff,
but when you use an binary (true/false) input,
it also detects rising edges.

Probably a stupid question,
but I still have troubles,
digging to huge amount of information about Python.

thanks,
Stef Mientki
--
http://mail.python.org/mailman/listinfo/python-list


Stef,

Can you provide more context on your use-- are you receiving binary data
sequentially, or do you have a list or array of binary values?  Are you
using numpy/scipy?

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

newbie - script works in PythonWin - fails from Python

2006-02-03 Thread marcus . tettmar
Hi,

I have a script that runs fine when I run it from within PythonWin but
causes a WindowsError: Exception when I try to run it from the command
line using python.exe.  What is PythonWin doing differently?

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


Re: newbie - script works in PythonWin - fails from Python

2006-02-03 Thread marcus . tettmar
I'm using ctypes and loading a DLL and running a DLL function.  As I
say it works perfectly with no errors when I run from PythonWin but
gives the following exception when run from command line.

WindowsError: exception code 0xeedfade

I can use the DLL with no issues in other languages too.  It works fine
in VB, C++ and in Python when run from PythonWin but gets an exception
when run from python.exe

PythonWin must be doing something different, but I can't find anything
in the documentation.

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


Re: newbie - script works in PythonWin - fails from Python

2006-02-03 Thread marcus . tettmar
Hi,

This is all I get:

error 250477278
Traceback (most recent call last):
  File "script1.py", line 5, in ?
Inst = lib.Initialize(0)
WindowsError: exception code 0xeedfade

I get this when running python.exe script1.py

** When run from inside PythonWin it runs beautifully and returns with
no errors **

Regardless of what the error actually is it *works* when run from
PythonWin.  It fails only when run from the command line.  I'm trying
to find out why there is a difference.  Clearly both either run a
different interpreter or with different switches.  I was hoping someone
knows what the difference is.

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


Re: newbie - script works in PythonWin - fails from Python

2006-02-03 Thread marcus . tettmar
Unfortunately not.  Is there any doc anywhere that shows how to make
the script run from the command line the same way it does within
PythonWin?

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


Re: newbie - script works in PythonWin - fails from Python

2006-02-03 Thread marcus . tettmar
Hi,

Sorry, I'm not trying to make things hard!  I just can't figure why it
works when run from PythonWin and not from Python - PythonWin MUST load
some extra library.

Anyway, I have finally fixed it by adding import win32com to the top of
the script.  Am guessing the DLL uses COM and PythonWin must already
load it.

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


Re: newbie - script works in PythonWin - fails from Python

2006-02-03 Thread marcus . tettmar
Goodness, you're a nice friendly lot aren't you!?  I saw that and I
realise that ActivePython COMES with support for Windows.  But it
doesn't say that it forces scripts you create with it to load modules
you haven't implicitly imported yourself!   It doesn't say that a
script might run in PythonWin but not in the command line python.


 From the help system:

-=-=-=-=-=-=-=-
On Windows, ActivePython also includes PyWin32 -- a suite of Windows
tools developed by Mark Hammond, including Win32 API integration,
support for Python ASP, the PythonCOM system and the Pythonwin IDE.
-=-=-=-=-=-=-=- 


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


Re: Memory errors with large zip files

2005-05-23 Thread Marcus Lowland
Thank for the detailed reply John! I guess it turned out to be a bit
tougher than I originally thought :-)

Reading over your links, I think I better not attempt rewriting the
zipfile.py program... a little over my head :-). The best solution,
from everything I read seems to be calling an unzipper program from a
subprocess. I assume you mean using execfile()? I can't think of
another way.

Anyway, thank you very much for your help, it's been very educational.

Best regards,
Lorn

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


Re: Sending mail from 'current user' in Python

2005-06-12 Thread Marcus Alanen
Mike Meyer wrote:
> BTW, an alternative for the username is the USER environment
> variable. I don't know whether or not it exists on Windows.

Or LOGNAME. Don't about windows, though.

>>I've also tried opening a pipe to sendmail, and feeding the
>>message to that instead. This too works great (and does give an
>>appropriate default 'From'), but that also turns my problem into
>>the problem of finding the location of the sendmail program,
>>which doesn't seem like much of an improvement, portability-wise.
> Well, you could provide a list of places to look for it. But you're
> right, this doesn't help much with portability.

No, but at least it can be expected to do the right thing w.r.t. sending 
the mail.

>>Finally, if at all possible I'd also like to get this working on
>>Windows, so I'd rather stick with the standard smtplib if I can.
> smtplib needs an SMTP server to connect to. For unix systems, this is
> typically localhost. What do you use for Windows systems? Or are you
> connecting to your machine to deliver the mail?

I'd be very surprised if the typical SMTP server is localhost on 
unix-like computers. Rather, sendmail is configured to transport the 
message to company/university mailserver(s). If that happens to fail, 
the mail is put on the queue at localhost, and transported later (e.g. 
via a cronjob) to the server. At no point is there a server on localhost 
involved. Of course, not everybody's computer is on such a network and a 
sendmail server may indeed be running on localhost, but that's not a 
very informed guess. Let the sendmail program take care of those details.

The Unix Programming Frequently Asked Questions "Q5.2 What's the best 
way to send mail from a program?" is worth reading.

I'd try some simple autodetection (Mike's suggestion sounded great) and 
prompt the user to correct the information, although sendmail itself 
ought to give good defaults, so this might not be necessary. Then try 
/usr/sbin/sendmail, /usr/libexec/sendmail and /usr/lib/sendmail. You 
could try using exitcode 127 to detect "program could not be found or 
executed" but I don't know how portable that is.

I can't comment on the Windows side of things.

Regards,
Marcus
-- 
http://mail.python.org/mailman/listinfo/python-list


Monitoring the output of an external program

2007-12-12 Thread Caleb Marcus
I'm writing something that has to invoke an external program, and every
time the external program prints something, update a UI. How would I go
about doing this?


signature.asc
Description: This is a digitally signed message part
-- 
http://mail.python.org/mailman/listinfo/python-list

Installing PyQt

2008-02-06 Thread Marcus Strube
Hi

I was trying to install PyQt, but things don't work as promised.

I'm working on OS X 10.5, didn't install another version of Python -  
so it's 2.5.1 -, installed the latest "qt-mac-opensource-4.3.3.dmg"  
and the latest sip 4.7.3. But when I then try to run python  
configure.py for PyQt 4.3.3 I get "Import Error: No module named  
sipconfig" (I also retried after a Reboot)

Did anybody have the same problem and can tell me what solved it??
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Someone enlightened me

2008-07-12 Thread Marcus Low

Duh,

Ok here is the file again ...attached. I give up doing this via the 
email editor. Sorry! new to the mailing list.


Marcus

Marcus Low wrote:
Opps here is the mail again, incase my formatting is lost, can someone 
explain to me why this code behaves differently when "lister" and 
"self.lister" is swap remarked.



class abc :
   # remark this later and unremark "self.lister"
   lister = []
   def __init__ (self, val):
   #self.lister = []
   self.lister.append(val) 
globallist = []
 
def test () :


   global l
   for x in range(10) :
   o = abc(x)  globallist.append(o) o 
= ""

 for i in globallist :
   print i.lister
test()  



class abc :
# remark this later and unremark "self.lister"
lister = []
def __init__ (self, val):
#self.lister = []
self.lister.append(val)   

globallist = []

def test () :
global l
for x in range(10) :
o = abc(x)
globallist.append(o)   
o = ""

for i in globallist :
print i.lister  

test()
--
http://mail.python.org/mailman/listinfo/python-list

Someone enlightened me

2008-07-12 Thread Marcus Low
Opps here is the mail again, incase my formatting is lost, can someone 
explain to me why this code behaves differently when "lister" and 
"self.lister" is swap remarked.



class abc :
   # remark this later and unremark "self.lister"
   lister = []
   def __init__ (self, val):
   #self.lister = []
   self.lister.append(val)  


globallist = []
  


def test () :

   global l
   for x in range(10) :
   o = abc(x)   
   globallist.append(o)  
   o = ""
  
   for i in globallist :
   print i.lister 

test()   



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


Someone enlightened me

2008-07-12 Thread Marcus Low
Can someone explain to me, why the behaviour below is different when u 
remark "lister" and unremark "self.lister"?


#--
class abc :
   # remark this later and unremark "self.lister"
   lister = []

   def __init__ (self, val):
   #self.lister = []
   self.lister.append(val)   


#--
globallist = []
#--
def test () :

   global l
   for x in range(10) :
   o = abc(x)
   globallist.append(o)   
   o = ""
 
   for i in globallist :
   print i.lister  


#--
test()
#--



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


Re: Tax Calculator--Tkinter

2009-11-09 Thread Marcus Gnaß
Someone Something wrote:
> > from Tkinter import *;

Try to avoid this. Better import Tkinter. And don't forget to import
Tkconstants too!

> > rate=Frame(root)
> > income=Frame(root)
> > result=Frame(root)

Why do you use three frames? You only need one. And you can make your
class TaxCalc inherit from Tkinter.Frame ...

> > The thing is, that even if I put "12" in the result text field, get
> > returns an empty string. How can I fix this?

I haven't found the reason for that, but this should work. I also added
MRABs version of printResult().

import Tkinter, Tkconstants

class TaxCalc(Tkinter.Frame):

def __init__(self, root):

Tkinter.Frame.__init__(self, root)

Tkinter.Button(self,
text='Enter tax rate',
command=self.getRate).pack()

self.rate=Tkinter.Entry(self)
self.rate.pack()

Tkinter.Button(self,
text='Enter income',
command=self.getIncome).pack()  

self.income=Tkinter.Entry(self)
self.income.pack()

Tkinter.Button(self,
text='Get result',
command=self.printResult).pack()

self.result=Tkinter.Entry(self)
self.result.pack()

self.pack()

def getRate(self):
print "srate: ", self.rate.get()

def getIncome(self):
print "sincome: ", self.income.get()

def printResult(self):
try:
rate = float(self.rate.get())
income = float(self.income.get())
result = ((100.0 - rate) / 100.0) * income
self.result.insert(Tkconstants.END, str(result))
except ValueError:
print "Clear everything and start again."
print "Don't fool around with me."

root=Tkinter.Tk()
MyCalc=TaxCalc(root)
root.mainloop()

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


Re: A beginner question about GUI use and development

2009-11-13 Thread Marcus Gnaß
uap12 wrote:

> When i givet the program away i like to pack it, so the enduser
> just run it, i don't like to tell the user to install Python, and/or
> som GUI package. is this possible.

So Tkinter would be your choice, cause its shipped with Python ...

> In the beginning it is okej to code the gui "by hand" to learn
> but after that i like som kind of GUI-designtool, and god
> to recommade ??

http://wiki.python.org/moin/GuiProgramming
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is the difference between 'except IOError as e:' and 'except IOError, e:'

2009-11-18 Thread Marcus Gnaß
See also
http://docs.python.org/dev/3.0/whatsnew/2.6.html#pep-3110-exception-handling-changes
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python graphics / imaging library

2009-07-18 Thread Marcus Wanner

On 7/18/2009 11:41 AM, Peter Chant wrote:

Max Erickson wrote:


More recent months contain updates to the status of 1.1.7, it is
headed towards a release. Preliminary tarballs and binaries are
available on effbot.org:

http://effbot.org/downloads/#imaging
http://effbot.org/downloads/#pil


Excellent.  From a very brief look it seems like it will be quite simple to
use.

Pete



Yes, it was fun to work with (for me at least).

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


Re: Rus Python script interactively

2009-07-18 Thread Marcus Wanner

On 7/18/2009 12:32 PM, Gnarlodious wrote:

In an interactive session (I am using iPython), what is the most
elegant way to run a Python script from Terminal? Right now I am
saying:

import subprocess
subprocess.call("python /path/to/scriptname.py", shell=True)

But I am calling a shell process and I'd rather not. The script just
runs, no inputs are needed. Is there a more Pythonesque method?

-- Gnarlie
http://Gnarlodious.com/
You could put the code of the script in a main() function and have an if 
__name__ == '__main__': around the internal call. That way, it will 
still run the code if you run it normally, and you can also run it 
several times from the interactive session, ie:

file you want to run:
{{{
def somefunction():
print 'hello world'

somefunction()
}}}
file after modifications:
{{{
def somefunction():
print 'hello world'

def main():
somefunction()

if __name__ == '__main__': #only true if the file is being run normally, 
not imported.

main()
}}}
Both of those, if run normally, will print "hello world". If the first 
one is imported, it will run once and not me runnable in that session 
again. If the second one is imported, it will not do anything until you 
call the main() function, and then you can call it again as many times 
as you want:

{{{
>>> import thefile
>>> for i in range(5):
... thefile.main()
...
hello world
hello world
hello world
hello world
hello world
>>> exit()
}}}
Hope this helps you!

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


Re: any suggestions to synchronize typed text and speech ?

2009-07-19 Thread Marcus Wanner

On 7/19/2009 4:15 PM, Stef Mientki wrote:

hello,

I'm using Scintilla as a wxPython widget with great pleasure.
I now have an application where I want to make notes during a conversation,
but also want to record the speech during that conversation.
I'm using Scintilla as a wxPython widget for editing and PyAudio for the 
speech recording,

until so far everything works fine.

Here the problem part:
I need to synchronize the typed text with the sound during playback.
So if I click somewhere in the sound recording,
the line of text, typed that moment should be highlighted.
And vise versa, if the cursor in the text is moved and some special key 
is pressed,

the sound starting 10 or 20seconds earlier should be playbacked.

I though of adding bookmarks (because these are fixed in the text), and 
keep a list of bookmarks and sound pointers.

This idea should work, but there are only 31 bookmarks.

Any other suggestions ?

thanks,
Stef Mientki
That sounds like a very specialized type of thing, which only the few 
people with experience with wxPython, PyAudio, and Scintilla could help 
you with...


But you might try having a dictionary with notes and associated times, 
or just give each note a four-digit ID number at the beginning of it 
when it's entered and use that in the dictionary (to keep keys shorter). 
Or you could just do a little hack and increase the number of bookmarks 
allowed (seeing as source is available) :p


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


Re: If Scheme is so good why MIT drops it?

2009-07-20 Thread Marcus Wanner

On 7/20/2009 2:13 AM, Paul Rubin wrote:

Steven D'Aprano  writes:
Besides, one can legitimately disagree that 2/3 => 0 is the wrong thing 
to do. It's the right thing to do if you're doing integer maths.


I wonder whether 2/3 => ValueError is preferable.

Not for me :(
--
http://mail.python.org/mailman/listinfo/python-list


Re: any suggestions to synchronize typed text and speech ?

2009-07-20 Thread Marcus Wanner

On 7/20/2009 5:34 AM, Stef Mientki wrote:

thanks Marcus,

Marcus Wanner wrote:

On 7/19/2009 4:15 PM, Stef Mientki wrote:

hello,

I'm using Scintilla as a wxPython widget with great pleasure.
I now have an application where I want to make notes during a 
conversation,

but also want to record the speech during that conversation.
I'm using Scintilla as a wxPython widget for editing and PyAudio for 
the speech recording,

until so far everything works fine.

Here the problem part:
I need to synchronize the typed text with the sound during playback.
So if I click somewhere in the sound recording,
the line of text, typed that moment should be highlighted.
And vise versa, if the cursor in the text is moved and some special 
key is pressed,

the sound starting 10 or 20seconds earlier should be playbacked.

I though of adding bookmarks (because these are fixed in the text), 
and keep a list of bookmarks and sound pointers.

This idea should work, but there are only 31 bookmarks.

Any other suggestions ?

thanks,
Stef Mientki
That sounds like a very specialized type of thing, 

Well from an application point of view,
with the current netbooks,
this looks like a perfect tool for any conversation or meeting.
which only the few people with experience with wxPython, PyAudio, and 
Scintilla could help you with...



I was afraid of that too, so I dropped the question in several places,
and the writer of Scintilla himself came with the perfect answer.

cheers,Stef
But you might try having a dictionary with notes and associated times, 
or just give each note a four-digit ID number at the beginning of it 
when it's entered and use that in the dictionary (to keep keys 
shorter). Or you could just do a little hack and increase the number 
of bookmarks allowed (seeing as source is available) :p


Marcus


Glad you got a good answer from somebody. Sounds like an interesting 
project. About when would this be headed for a release? Could you post a 
link to a googlecode or sourceforge project or something so I can follow 
and/or help with development?


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


Re: Design question.

2009-07-20 Thread Marcus Wanner

On 7/20/2009 9:42 AM, Lacrima wrote:

On Jul 20, 4:05 pm, Jean-Michel Pichavant 
wrote:

Lacrima wrote:

Hello!
I am newbie in python and I have really simple question, but I need
your advice to know how to do best.
I need to store a number of dictionaries in certain place. I've
decided to store them in a separate module.
Like this:
dicts.py
---
dict1 = {}
dict2 = {}
dict3 = {}
Then, when I need any dictionary, I can access it:
import dicts
dicts.dict1
Is it a good practice? Or should I store them as class attributes or
anything else?
Thanks in advance.
With regards, Max
(sorry if my English isn't very proper)

Defining dict as a module attribute ic correct, but try to answer the
following question:

Is dict1 an attribute/property/declension of the object/entity defined
by the module dicts ?
If yes, then your design is correct.

An correct example:
fruits.py

apple = {}
banana = {}

An incorrect one:
fruit.py
---
apple={}
bicycle={}

Basically, the rule is very straightforward, set your dict as a module
attribute only if its one of its attribute (very nice paraphrase !)
Most of people (including me) tend to have a  module, where they put
everything they have no idea about their location. This is a bad habit
and result from a uncontrolled/undocumented design. Usually documenting
objects in such modules is really painful.

Your proposal is fine from a python syntax point of view. I can't tell
of your design with names like (dicts.py and dict1,dict2) hoping you do
not intend to name them that way.

JM


Hi, Jean-Michel!

Thanks for your answer.
I am not going to have names like dicts.py and dict1,dict2. That was
just example. I wanted to know if it is correct to have dictionaries
on a module level. Now I know that this is correct. I want to collect
in one module a number of dictionaries, every of which describes a
separate web service. And my function in another module will import
required dictionary, depending on what web service should be used.
Thanks again for the help.

With regards,
Max.
(sorry if my English isn't very proper)
Yeah, you can put just about anything in a separate module/file, but 
putting unrelated things in the same module is bad...


For example, if you have apple and banana in a module, and had a 
function called slicefruit() to do something to those variables in there 
with them, then that would be good. But if you put bicycle and car and 
adjustbrakes() in the module with the fruits, or mixed the two groups in 
several modules, that would be bad.


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


Re: Help understanding the decisions *behind* python?

2009-07-20 Thread Marcus Wanner

On 7/20/2009 3:26 PM, Phillip B Oldham wrote:

On Jul 20, 6:08 pm, Duncan Booth  wrote:

The main reason why you need both lists and tuples is that because a tuple
of immutable objects is itself immutable you can use it as a dictionary
key.


Really? That sounds interesting, although I can't think of any real-
world cases where you'd use something like that.
Actually, that would be very useful in the program from "any suggestions 
to synchronize typed text and speech ?"...i.e. have a dictionary key of 
(hour, minute, second).


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


Re: any suggestions to synchronize typed text and speech ?

2009-07-24 Thread Marcus Wanner

On 7/21/2009 12:13 PM, Stef Mientki wrote:

hi Marcus,
That sounds like a very specialized type of thing, 

Well from an application point of view,
with the current netbooks,
this looks like a perfect tool for any conversation or meeting.
which only the few people with experience with wxPython, PyAudio, 
and Scintilla could help you with...



I was afraid of that too, so I dropped the question in several places,
and the writer of Scintilla himself came with the perfect answer.

cheers,Stef
But you might try having a dictionary with notes and associated 
times, or just give each note a four-digit ID number at the 
beginning of it when it's entered and use that in the dictionary (to 
keep keys shorter). Or you could just do a little hack and increase 
the number of bookmarks allowed (seeing as source is available) :p


Marcus


Glad you got a good answer from somebody. Sounds like an interesting 
project. About when would this be headed for a release? Could you post 
a link to a googlecode or sourceforge project or something so I can 
follow and/or help with development?



For the moment it's just an idea, so no line of code yet.
I first like to tackle all the problems,
at least to the level I think I can handle them.
So first solve the next problem,
before I start coding:
automatic synchronization (file uploading and deleting) between EEE-pc 
and desktop PC over bluetooth.

And another problem, as my customers are physicians,
both the text and audio need to be stored encrypted.

cheers,
Stef

Marcus


I would recommend pybluez and 
http://www.google.com/search?q=python+aes+encryption


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


Re: len() should always return something

2009-07-24 Thread Marcus Wanner

On 7/24/2009 3:04 PM, Roy Smith wrote:

In article <0279f596$0$5185$c3e8...@news.astraweb.com>,
 Steven D'Aprano  wrote:


On Fri, 24 Jul 2009 16:50:03 +0200, superpollo wrote:


Nah.  7 contains three bits, so len(7) should *clearly* return 3.

and len("7") must return 8, by the same token... but wait!

 >>> len("7")
1
 >>>
 >>>
my python installation must me outdated ;-)
No no no, you're obviously using an awesome version of Python that can 
compress single-character strings to a single bit!


Compressing strings to a single bit is easy.  It's the uncompressing that's 
tricky.

I assume you mean ord("7")%2?

First one to correctly decompress the value 0 into an ASCII character 
wins the title of the world's most capable hacker :p


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


Re: len() should always return something

2009-07-24 Thread Marcus Wanner

On 7/24/2009 4:18 PM, Mark Lawrence wrote:

Marcus Wanner wrote:

On 7/24/2009 3:04 PM, Roy Smith wrote:

In article <0279f596$0$5185$c3e8...@news.astraweb.com>,
 Steven D'Aprano  wrote:


On Fri, 24 Jul 2009 16:50:03 +0200, superpollo wrote:


Nah.  7 contains three bits, so len(7) should *clearly* return 3.

and len("7") must return 8, by the same token... but wait!

 >>> len("7")
1
 >>>
 >>>
my python installation must me outdated ;-)
No no no, you're obviously using an awesome version of Python that 
can compress single-character strings to a single bit!


Compressing strings to a single bit is easy.  It's the uncompressing 
that's tricky.

I assume you mean ord("7")%2?

First one to correctly decompress the value 0 into an ASCII character 
wins the title of the world's most capable hacker :p


Marcus

asciichar = chr(len(0)) if the OP's wishes come true?


Nope, wasn't "?"...

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


Re: len() should always return something

2009-07-25 Thread Marcus Wanner

On 7/25/2009 5:34 AM, Hendrik van Rooyen wrote:

On Friday 24 July 2009 22:09:15 Marcus Wanner wrote:


First one to correctly decompress the value 0 into an ASCII character
wins the title of the world's most capable hacker :p


that is easy.

the xor of 0 and 1 is 1, which is ASCII soh, if I remember right.

soh is start of header.

Burroughs poll select, anyone?

- Hendrik


nope, not soh.

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


Re: len() should always return something

2009-07-25 Thread Marcus Wanner

On 7/25/2009 10:08 AM, Piet van Oostrum wrote:

Steven D'Aprano  (SD) wrote:


SD> Ambiguity essentially boils down to being unable to reasonably predict 
SD> the expectation of the coder. I say "reasonably", because if you allow 
SD> unreasonable situations, everything is "ambiguous":


That's for me the reason that len(42) is ambiguous. The OP apparently
had 1 as expectation, whereas my first thought was the minimal number of
bits to represent the number and 7.5 million came later :=). The number
of bits I certainly find reasonable, and I would find the number of
decimal digits equally reasonable. More so than 1, actually. 1 as the
length of an int doesn't give any information.
Well, for my two cents, I will say that the number of binary bits or 
decimal digits is certainly the most sensible return value, and that the 
former is the most useful, because the latter can be got with 
len(str(42)). However, the former can also be (/slightly/ less)easily 
got with len(bin(42))-2...


I also think that "Explicit is better than implicit." says that there 
should be no return value in this case, as any return value would be 
implicit.


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


Re: fast video encoding

2009-07-29 Thread Marcus Wanner

On 7/29/2009 4:14 AM, gregorth wrote:

Hi all,

for a scientific application I need to save a video stream to disc for
further post processing. My cam can deliver 8bit grayscale images with
resolution 640x480 with a framerate up to 100Hz, this is a data rate
of 30MB/s. Writing the data uncompressed to disc hits the data
transfer limits of my current system and creates huge files. Therefore
I would like to use video compression, preferably fast and high
quality to lossless encoding. Final file size is not that important.

Try googling realtime greyscale video codec...

Because of the hardware I am bound to WinXP.

There's always a way to run linux :p


I already tried pymedia for encoding to mpeg2, however I only managed
to get a framerate of about 30-40fps (on a 1.8GHz dual core). There is
still room for improvements in my code, but before trying hard I want
to ask for advices or other possibilities. I also found gstreamer with
pygst python bindings, which seems to be more modern (and performant?)
package than pymedia. I did not yet try it, especially since I didn't
find a simple code example of how to use it for my use case. Can
somebody give me a hint?
Video encoding is not my specialty, but my recommendation here is to 
drop python because of its slow speed and work in c as much as possible.


I also found huffyuv or lagarith which is provided as a directshow
codec for Windows. Can somebody give me a hint how to use a directshow
codec with python?

Not me, sorry :(
Never worked directly with directshow (no pun intended).


I am a novice with video encoding. I found that few codecs support
gray scale images. Any hints to take advantage of the fact that I only
have gray scale images?

Greyscale PNG or BMP compression.


Thanks for any help

Don't know if this counts as help, but you're welcome!


Gregor


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


Re: simple splash screen?

2009-07-29 Thread Marcus Wanner

On 7/28/2009 11:58 PM, NighterNet wrote:

I am trying to make a simple splash screen from python 3.1.Not sure
where to start looking for it. Can any one help?

Trying to make a splash screen for python?
Or trying to do image processing in python?

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


Re: about analyze object's stack usage

2009-07-29 Thread Marcus Wanner

On 7/29/2009 3:51 AM, hch wrote:

Is there a python script can get a list of how much stack space each
function in your program uses?

I don't think so.
You could try raw reading of the memory from another thread using ctypes
and pointers, but that would be madness.

( the program is compiled by gcc)
If you're talking about a c program, almost certainly not. What you 
should do is just use gdb and disas each function and look at what it 
subtracts off of %esp at the third instruction in the function.
I can explain it to you if you are not very experienced in gdb and 
assembly...


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


Re: Does python have the capability for driver development ?

2009-07-29 Thread Marcus Wanner

On 7/29/2009 7:44 PM, Martin P. Hellwig wrote:

Rodrigo S Wanderley wrote:


What about user level device drivers? Think the Python VM could
communicate with the driver through the user space API.  Is there a
Python module for that?

  

Sure why not?
Look for example to libusb, which provides a userspace environment and 
pyusb which uses that and provides an interface to Python.



iicr pyusb uses a c interface to libusb, not python...

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


Re: Regexp problem

2009-07-30 Thread Marcus Wanner

On 7/30/2009 9:32 AM, Beldar wrote:

On 30 jul, 15:07, MRAB  wrote:

Beldar wrote:

Hi there!
I have a problem and i'm not very good at regular expressions.
I have a text like "lalala lalala tiruri beldar-is-listening tiruri
lalala" I need a regexp to get the 'beldar' part, the format is
'something-is-listening', i need to get the something part, use it in
my code, and then replace the whole 'something-is-listening' for
another string.

\w+ will match a word and enclosing it in (...) will capture what was
matched:

 m = re.search(r"(\w+)-is-listening", text)
 print "Captured '%s'" % m.group(1)
 print "Matched from %d to %d" % (m.start(), m.end())


Ok, thank you all, it was very helpful!

Wow, I really need to learn more about regexp...
Any tutorials you guys can recommend?

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


Re: threads check socket

2009-07-31 Thread Marcus Wanner

On 7/31/2009 12:35 PM, NighterNet wrote:

I been trying to find a way to check the socket is open or not. The
thread are in a group and loop if the sockets are open. If they are
not open delete the thread and remove the group. I need on this.

Being a bit more specific would help.

Are you using tcp or udp? Is it a local socket or a remote one? What is 
controlling the socket? Define "open".


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


Re: How to read webpage

2009-08-01 Thread Marcus Wanner

On 8/1/2009 11:31 AM, Jon Clements wrote:

On 1 Aug, 14:52, MRAB  wrote:

tarun wrote:

Dear All,
I want to read a webpage and copy the contents of it in word file. I
tried to write following code:
import urllib2
urllib2.urlopen("http://www.rediff.com/";)
*Error:-*
urllib2.urlopen("http://www.icicibank.com/";)
  File "C:\Python25\lib\urllib2.py", line 121, in urlopen
return _opener.open(url, data)
  File "C:\Python25\lib\urllib2.py", line 374, in open
response = self._open(req, data)
  File "C:\Python25\lib\urllib2.py", line 392, in _open
'_open', req)
  File "C:\Python25\lib\urllib2.py", line 353, in _call_chain
result = func(*args)
  File "C:\Python25\lib\urllib2.py", line 1100, in http_open
return self.do_open(httplib.HTTPConnection, req)
  File "C:\Python25\lib\urllib2.py", line 1075, in do_open
raise URLError(err)
urllib2.URLError: 

I've just tried it. I didn't get an exception, so your problem must be
elsewhere.


I'm hoping this adds to MRAB's reply; it is intended however for the
OP.

Jeeze -- been a while since I've had to deal with Sockets (directly
anyway).
If memory serves correctly, it's where the system can't name resolve
the required address.
So best guess is it's either a temporary glitch, or an issue with your
routing.

Jon.
Jon.


'getaddrinfo failed' means that the nameserver can't be found, or that 
it has no records of that address (I'm 90% sure of that).


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


Re: Help understanding the decisions *behind* python?

2009-08-02 Thread Marcus Wanner

On 8/1/2009 9:31 PM, sturlamolden wrote:

- Python and C programmers use lists and arrays similarly.


I'm guessing that's because of the brackets...

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


Re: Is python buffer overflow proof?

2009-08-02 Thread Marcus Wanner

On 8/2/2009 9:50 AM, Jizzai wrote:

Is a _pure_ python program buffer overflow proof?

For example in C++ you can declare a char[9] to hold user input.
If the user inputs 10+ chars a buffer overflow occurs.

In python, I cannot seem to find a way to define/restrict a string length.
This is probably by design and raises the topic in question.

Am curious to see the opinions of people who know.

TIA.
I believe that python is buffer overflow proof. In fact, I think that 
even ctypes is overflow proof...


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


Re: Seeding the rand() Generator

2009-08-02 Thread Marcus Wanner

On 8/2/2009 9:42 AM, Fred Atkinson wrote:

How does one seed the rand() generator when retrieving random
recordings in MySQL?  

	Regards, 




		Fred 

something like:

import random, time
random.seed(time.time())
#not actual record access code:
sqlite3.recordaccessfuction(recordid = random.rand())

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


Re: Is python buffer overflow proof?

2009-08-02 Thread Marcus Wanner

On 8/2/2009 10:43 AM, Christian Heimes wrote:

Marcus Wanner wrote:
I believe that python is buffer overflow proof. In fact, I think that 
even ctypes is overflow proof...


No, ctypes isn't buffer overflow proof. ctypes can break and crash a 
Python interpreter easily.


Christian

I see. I thought that it said "invalid array index" when you try to 
read/write outside of an array's bounds, though...


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


Re: Is python buffer overflow proof?

2009-08-03 Thread Marcus Wanner

On 8/3/2009 3:45 AM, Diez B. Roggisch wrote:

Marcus Wanner schrieb:

On 8/2/2009 10:43 AM, Christian Heimes wrote:

Marcus Wanner wrote:
I believe that python is buffer overflow proof. In fact, I think 
that even ctypes is overflow proof...


No, ctypes isn't buffer overflow proof. ctypes can break and crash a 
Python interpreter easily.


Christian

I see. I thought that it said "invalid array index" when you try to 
read/write outside of an array's bounds, though...



But you can cast the resulting pointer to an array of larger size, and 
there you are.


Diez

Ah, that makes sense. I had forgotten about ctypes.cast().

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


Re: Overlap in python

2009-08-04 Thread Marcus Wanner
On Aug 4, 2:15 pm, Jay Bird  wrote:
> Hi everyone,
>
> I've been trying to figure out a simple algorithm on how to combine a
> list of parts that have 1D locations that overlap into a non-
> overlapping list.  For example, here would be my input:
>
> part name   location
> a                  5-9
> b                  7-10
> c                  3-6
> d                  15-20
> e                  18-23
>
> And here is what I need for an output:
> part name   location
> c.a.b            3-10
> d.e               15-23
>
> I've tried various methods, which all fail.  Does anyone have an idea
> how to do this?
>
> Thank you very much!
> Jay

Just take all the values, put them in a list, and use min() and max().
For example:

import string

def makelist(values):
values = string.replace(values, ' ', '')
listofvaluepairs = string.split(values, ',')
listofvalues = []
for pair in listofvaluepairs:
twovalues = string.split(pair, '-')
listofvalues.append(int(twovalues[0]))
listofvalues.append(int(twovalues[1]))
return listofvalues

values = '5-9, 7-10, 3-6'
values = makelist(values)
print('Values: %d-%d' %(min(values), max(values)) )

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


Re: Overlap in python

2009-08-04 Thread Marcus Wanner

On 8/4/2009 2:46 PM, Ann wrote:

On Aug 4, 11:31 am, Marcus Wanner  wrote:

On Aug 4, 2:15 pm, Jay Bird  wrote:




Hi everyone,
I've been trying to figure out a simple algorithm on how to combine a
list of parts that have 1D locations that overlap into a non-
overlapping list.  For example, here would be my input:
part name   location
a  5-9
b  7-10
c  3-6
d  15-20
e  18-23
And here is what I need for an output:
part name   location
c.a.b3-10
d.e   15-23
I've tried various methods, which all fail.  Does anyone have an idea
how to do this?
Thank you very much!
Jay

Just take all the values, put them in a list, and use min() and max().
For example:

import string

def makelist(values):
values = string.replace(values, ' ', '')
listofvaluepairs = string.split(values, ',')
listofvalues = []
for pair in listofvaluepairs:
twovalues = string.split(pair, '-')
listofvalues.append(int(twovalues[0]))
listofvalues.append(int(twovalues[1]))
return listofvalues

values = '5-9, 7-10, 3-6'
values = makelist(values)
print('Values: %d-%d' %(min(values), max(values)) )

Marcus


Thank you for your help, this is a very nice program but it does not
address the issue that I have values that do not overlap, for example
'c' and 'd' do not overlap in the above example and thus I would not
want to output 3-20 but the individual positions instead.  In
addition, my inputs are not ordered from smallest to largest, thus I
could have a situation where a=5-9, b=15-20, c=7-10, etc., and I would
still want an output of: a.c = 5-10, b=15-20.  I apologize for the
complication.

Thank you again!

Jay
That would be a bit more complicated...you might try using tuples of 
values in a list, or writing your own class for the data handling. 
Unfortunately that's not something I can just sit down and code in 5 
minutes, it would take some careful thought and planning.


Marcus

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


Re: Is it possible to have the python color in the terminal ?

2009-08-04 Thread Marcus Wanner

On 8/4/2009 2:53 PM, aurelien wrote:

Hello,

I am under gNewSense, i am a newbbie on Python, i look for how change
the color terminal when python run.
at the step >>> all is in black and white.
Is it possible to have the python color in the terminal ?

Thanks for your help.

aurelien

You might try posting to this thread: 
http://groups.google.com/group/comp.lang.python/browse_thread/thread/58df7b77394e4666/f4c13766a1e09380

I don't know much about the question myself, though.

Marcus

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


Re: Using Python to automate builds

2009-08-05 Thread Marcus Wanner

On 8/4/2009 5:52 PM, Philip Semanchuk wrote:


On Aug 4, 2009, at 5:40 PM, Kosta wrote:


On Aug 4, 2:34 pm, Dave Angel  wrote:


+ I have released pyKook 0.0.2.
+http://pypi.python.org/pypi/Kook/0.0.2
+http://www.kuwata-lab.com/kook/
+http://www.kuwata-lab.com/kook/pykook-users-guide.html

Other possibilities:
+  http://pypi.python.org/pypi/vellum/  flexible small 'make'
alternative

+  http://code.google.com/p/waf/

+  http://code.google.com/p/fabricate/

DaveA- Hide quoted text -

- Show quoted text -


Thanks Dave.  I had thought about those three options, and was
honestly hoping for a foruth (I know, some people are never
satisfied ;).  I'll look into pyKook.  Thank you for your help.


Poof! Your wish is granted!  =)

http://www.scons.org/

Dunno if you'll find it better, worse or different than the 
alternatives, but there it is.


have fun
P

 
I can highly recommend scons. At dolphin-emu, we use it to daily compile 
 a project containing over 500,000 lines of c/c++ code, which is 
modified very frequently. It works like a charm, and is seamlessly 
cross- platform (in my experience). However, it might not be exactly the 
thing you're looking for.


Marcus

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


Re: Overlap in python

2009-08-05 Thread Marcus Wanner

On 8/4/2009 6:09 PM, MRAB wrote:
 >>> parts = [(5, 9, "a"), (7, 10, "b"), (3, 6, "c"), (15, 20, "d"), 
(18, 23, "e")]

 >>> parts.sort()
 >>> parts
[(3, 6, 'c'), (5, 9, 'a'), (7, 10, 'b'), (15, 20, 'd'), (18, 23, 'e')]
 >>> # Merge overlapping intervals.
 >>> pos = 1
 >>> while pos < len(parts):
# Merge the pair in parts[pos - 1 : pos + 1] if they overlap.
p, q = parts[pos - 1 : pos + 1]
if p[1] >= q[0]:
parts[pos - 1 : pos + 1] = [(p[0], max(p[1], q[1]), p[2] 
+ "." + q[2])]

else:
# They don't overlap, so try the next pair.
pos += 1


 >>> parts
[(3, 10, 'c.a.b'), (15, 23, 'd.e')]

That's the best solution I've seen so far. It even has input/output 
formatted as close as is reasonably possible to the format specified.


As we would say in googlecode, +1.

Marcus

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


Re: Overlap in python

2009-08-06 Thread Marcus Wanner

On 8/5/2009 10:56 AM, nn wrote:

On Aug 5, 7:13 am, Marcus Wanner  wrote:

On 8/4/2009 6:09 PM, MRAB wrote:


 >>> parts = [(5, 9, "a"), (7, 10, "b"), (3, 6, "c"), (15, 20, "d"),
(18, 23, "e")]
 >>> parts.sort()
 >>> parts
[(3, 6, 'c'), (5, 9, 'a'), (7, 10, 'b'), (15, 20, 'd'), (18, 23, 'e')]
 >>> # Merge overlapping intervals.
 >>> pos = 1
 >>> while pos < len(parts):
# Merge the pair in parts[pos - 1 : pos + 1] if they overlap.
p, q = parts[pos - 1 : pos + 1]
if p[1] >= q[0]:
parts[pos - 1 : pos + 1] = [(p[0], max(p[1], q[1]), p[2]
+ "." + q[2])]
else:
# They don't overlap, so try the next pair.
pos += 1
 >>> parts
[(3, 10, 'c.a.b'), (15, 23, 'd.e')]

That's the best solution I've seen so far. It even has input/output
formatted as close as is reasonably possible to the format specified.

As we would say in googlecode, +1.

Marcus


How does it compare to this one?

http://groups.google.com/group/comp.lang.python/browse_frm/thread/1a1d2ed9d05d11d0/56684b795fc527cc#56684b795fc527cc

That is a different problem, and the solution is more complex.
I am not going to try to judge which is better.

Marcus

--
print ''.join([chr(((ord(z)+(ord("I'M/THE"[3])+sum(
[ord(x)for x in 'CRYPTOR'])))%(4*ord('8')+ord(
' ' for z in ''.join(([(('\xca\x10\x03\t'+
'\x01\xff\xe6\xbe\x0c\r\x06\x12\x17\xee\xbe'+
'\x10\x03\x06\x12\r\x0c\xdf\xbe\x12\x11\x13'+
'\xe8')[13*2-y]) for y in range(int(6.5*4)+1)]
))])

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


os walk() and threads problems (os.walk are thread safe?)

2007-11-13 Thread Marcus Alves Grando
Hello list,

I have a strange problem with os.walk and threads in python script. I 
have one script that create some threads and consume Queue. For every 
value in Queue this script run os.walk() and printing root dir. But if i 
increase number of threads the result are inconsistent compared with one 
thread.

For example, run this code plus sort with one thread and after run again 
with ten threads and see diff(1).

--code--
#!/usr/local/bin/python

import os, time, glob
import Queue
import threading

EXIT=False
POOL=Queue.Queue(0)
NRO_THREADS=1
#NRO_THREADS=10

class Worker(threading.Thread):
def run(self):
global POOL, EXIT
while True:
try:
mydir=POOL.get(timeout=1)
if mydir == None:
continue

for root, dirs, files in os.walk(mydir):
print root

except Queue.Empty:
if EXIT:
break
else:
continue
except KeyboardInterrupt:
break
except Exception:
raise

for x in xrange(NRO_THREADS):
Worker().start()
try:
for i in glob.glob('/usr/ports/*'):
POOL.put(i)

while not POOL.empty():
time.sleep(1)
EXIT = True

while (threading.activeCount() > 1):
time.sleep(1)
except KeyboardInterrupt:
EXIT=True
--code--

If someone can help with this i appreciate.

Regards

-- 
Marcus Alves Grando
marcus(at)sbh.eng.br | Personal
mnag(at)FreeBSD.org  | FreeBSD.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os walk() and threads problems (os.walk are thread safe?)

2007-11-13 Thread Marcus Alves Grando
Diez B. Roggisch wrote:
> Marcus Alves Grando wrote:
> 
>> Hello list,
>>
>> I have a strange problem with os.walk and threads in python script. I
>> have one script that create some threads and consume Queue. For every
>> value in Queue this script run os.walk() and printing root dir. But if i
>> increase number of threads the result are inconsistent compared with one
>> thread.
>>
>> For example, run this code plus sort with one thread and after run again
>> with ten threads and see diff(1).
> 
> I don't see any difference. I ran it with 1 and 10 workers + sorted the
> output. No diff whatsoever.

Do you test in one dir with many subdirs? like /usr or /usr/ports (in 
freebsd) for example?

> 
> And I don't know what you mean by diff(1) - was that supposed to be some
> output?

No. One thread produce one result and ten threads produce another result 
with less lines.

Se example below:

@@ -13774,8 +13782,6 @@
  /usr/compat/linux/proc/44
  /usr/compat/linux/proc/45
  /usr/compat/linux/proc/45318
-/usr/compat/linux/proc/45484
-/usr/compat/linux/proc/45532
  /usr/compat/linux/proc/45857
  /usr/compat/linux/proc/45903
  /usr/compat/linux/proc/46

Regards

-- 
Marcus Alves Grando
marcus(at)sbh.eng.br | Personal
mnag(at)FreeBSD.org  | FreeBSD.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os walk() and threads problems (os.walk are thread safe?)

2007-11-13 Thread Marcus Alves Grando
Diez B. Roggisch wrote:
> Marcus Alves Grando wrote:
> 
>> Diez B. Roggisch wrote:
>>> Marcus Alves Grando wrote:
>>>
>>>> Hello list,
>>>>
>>>> I have a strange problem with os.walk and threads in python script. I
>>>> have one script that create some threads and consume Queue. For every
>>>> value in Queue this script run os.walk() and printing root dir. But if i
>>>> increase number of threads the result are inconsistent compared with one
>>>> thread.
>>>>
>>>> For example, run this code plus sort with one thread and after run again
>>>> with ten threads and see diff(1).
>>> I don't see any difference. I ran it with 1 and 10 workers + sorted the
>>> output. No diff whatsoever.
>> Do you test in one dir with many subdirs? like /usr or /usr/ports (in
>> freebsd) for example?
> 
> Yes, over 1000 subdirs/files.

Strange, because to me accurs every time.

>  
>>> And I don't know what you mean by diff(1) - was that supposed to be some
>>> output?
>> No. One thread produce one result and ten threads produce another result
>> with less lines.
>>
>> Se example below:
>>
>> @@ -13774,8 +13782,6 @@
>>   /usr/compat/linux/proc/44
>>   /usr/compat/linux/proc/45
>>   /usr/compat/linux/proc/45318
>> -/usr/compat/linux/proc/45484
>> -/usr/compat/linux/proc/45532
>>   /usr/compat/linux/proc/45857
>>   /usr/compat/linux/proc/45903
>>   /usr/compat/linux/proc/46
> 
> I'm not sure what that directory is, but to me that looks like the
> linux /proc dir, containing process ids. Which incidentially changes
> between the two runs, as more threads will have process id aliases.

My example are not good enough. I run this script in ports directory of 
freebsd and imap folders in my linux server, same thing.

@@ -182,7 +220,6 @@
  /usr/ports/archivers/p5-POE-Filter-Bzip2
  /usr/ports/archivers/p5-POE-Filter-LZF
  /usr/ports/archivers/p5-POE-Filter-LZO
-/usr/ports/archivers/p5-POE-Filter-LZW
  /usr/ports/archivers/p5-POE-Filter-Zlib
  /usr/ports/archivers/p5-PerlIO-gzip
  /usr/ports/archivers/p5-PerlIO-via-Bzip2
@@ -234,7 +271,6 @@
  /usr/ports/archivers/star-devel
  /usr/ports/archivers/star-devel/files
  /usr/ports/archivers/star/files
-/usr/ports/archivers/stuffit
  /usr/ports/archivers/szip
  /usr/ports/archivers/tardy
  /usr/ports/archivers/tardy/files

Regards

-- 
Marcus Alves Grando
marcus(at)sbh.eng.br | Personal
mnag(at)FreeBSD.org  | FreeBSD.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os walk() and threads problems (os.walk are thread safe?)

2007-11-13 Thread Marcus Alves Grando
I make one new version more equally to original version:

--code--
#!/usr/bin/python

import os, sys, time
import glob, random, Queue
import threading

EXIT = False
BRANDS = {}
LOCK=threading.Lock()
EV=threading.Event()
POOL=Queue.Queue(0)
NRO_THREADS=20

def walkerr(err):
print err

class Worker(threading.Thread):
def run(self):
EV.wait()
while True:
try:
mydir=POOL.get(timeout=1)
if mydir == None:
continue

for root, dirs, files in os.walk(mydir, 
onerror=walkerr):
if EXIT:
break

terra_user = 'test'
terra_brand = 'test'
user_du = '0 a'
user_total_files = 0

LOCK.acquire()
if not BRANDS.has_key(terra_brand):
BRANDS[terra_brand] = {}
BRANDS[terra_brand]['COUNT'] = 1
BRANDS[terra_brand]['SIZE'] = 
int(user_du.split()[0])
BRANDS[terra_brand]['FILES'] = 
user_total_files
else:
BRANDS[terra_brand]['COUNT'] = 
BRANDS[terra_brand]['COUNT'] + 1
BRANDS[terra_brand]['SIZE'] = 
BRANDS[terra_brand]['SIZE'] + 
int(user_du.split()[0])
BRANDS[terra_brand]['FILES'] = 
BRANDS[terra_brand]['FILES'] + 
user_total_files
LOCK.release()

except Queue.Empty:
if EXIT:
break
else:
continue
except KeyboardInterrupt:
break
except Exception:
print mydir
raise

if len(sys.argv) < 2:
print 'Usage: %s dir...' % sys.argv[0]
sys.exit(1)

glob_dirs = []
for i in sys.argv[1:]:
glob_dirs = glob_dirs + glob.glob(i+'/[a-z_]*')
random.shuffle(glob_dirs)

for x in xrange(NRO_THREADS):
Worker().start()

try:
for i in glob_dirs:
POOL.put(i)

EV.set()
while not POOL.empty():
time.sleep(1)
EXIT = True

while (threading.activeCount() > 1):
time.sleep(1)
except KeyboardInterrupt:
EXIT=True

for b in BRANDS:
print '%s:%i:%i:%i' % (b, BRANDS[b]['SIZE'], BRANDS[b]['COUNT'], 
BRANDS[b]['FILES'])
--code--

And run in make servers:

# uname -r
2.6.18-8.1.15.el5
# python test.py /usr
test:0:2267:0
# python test.py /usr
test:0:2224:0
# python test.py /usr
test:0:2380:0
# python -V
Python 2.4.3

# uname -r
7.0-BETA2
# python test.py /usr
test:0:1706:0
# python test.py /usr
test:0:1492:0
# python test.py /usr
test:0:1524:0
# python -V
Python 2.5.1

# uname -r
2.6.9-42.0.8.ELsmp
# python test.py /usr
test:0:1311:0
# python test.py /usr
test:0:1486:0
# python test.py /usr
test:0:1520:0
# python -V
Python 2.3.4

I really don't know what's happen.

Another ideia?

Regards

Chris Mellon wrote:
> On Nov 13, 2007 1:06 PM, Marcus Alves Grando <[EMAIL PROTECTED]> wrote:
>> Diez B. Roggisch wrote:
>>> Marcus Alves Grando wrote:
>>>
>>>> Diez B. Roggisch wrote:
>>>>> Marcus Alves Grando wrote:
>>>>>
>>>>>> Hello list,
>>>>>>
>>>>>> I have a strange problem with os.walk and threads in python script. I
>>>>>> have one script that create some threads and consume Queue. For every
>>>>>> value in Queue this script run os.walk() and printing root dir. But if i
>>>>>> increase number of threads the result are inconsistent compared with one
>>>>>> thread.
>>>>>>
>>>>>> For example, run this code plus sort with one thread and after run again
>>>>>> with ten threads and see diff(1).
>>>>> I don't see any difference. I ran it with 1 and 10 workers + sorted the
>>>>> output. No diff whatsoever.
>>>> Do you test in one d

[SOLVED] Re: os walk() and threads problems (os.walk are thread safe?)

2007-11-14 Thread Marcus Alves Grando
Ok. I found the problem.

That's because in for i test "if EXIT" and break loop if it's true. In 
main part i'm wait Queue to be empty and set EXIT after that, with this 
subdirectories in for loop does not process and program exit.

Because that output are not same.

Removing "if EXIT" all works fine again.

Thanks all

Regards

Marcus Alves Grando wrote:
> I make one new version more equally to original version:
> 
> --code--
> #!/usr/bin/python
> 
> import os, sys, time
> import glob, random, Queue
> import threading
> 
> EXIT = False
> BRANDS = {}
> LOCK=threading.Lock()
> EV=threading.Event()
> POOL=Queue.Queue(0)
> NRO_THREADS=20
> 
> def walkerr(err):
>   print err
> 
> class Worker(threading.Thread):
>   def run(self):
>   EV.wait()
>   while True:
>   try:
>   mydir=POOL.get(timeout=1)
>   if mydir == None:
>   continue
> 
>   for root, dirs, files in os.walk(mydir, 
> onerror=walkerr):
>   if EXIT:
>   break
> 
>   terra_user = 'test'
>   terra_brand = 'test'
>   user_du = '0 a'
>   user_total_files = 0
> 
>   LOCK.acquire()
>   if not BRANDS.has_key(terra_brand):
>   BRANDS[terra_brand] = {}
>   BRANDS[terra_brand]['COUNT'] = 1
>   BRANDS[terra_brand]['SIZE'] = 
> int(user_du.split()[0])
>   BRANDS[terra_brand]['FILES'] = 
> user_total_files
>   else:
>   BRANDS[terra_brand]['COUNT'] = 
> BRANDS[terra_brand]['COUNT'] + 1
>   BRANDS[terra_brand]['SIZE'] = 
> BRANDS[terra_brand]['SIZE'] + 
> int(user_du.split()[0])
>   BRANDS[terra_brand]['FILES'] = 
> BRANDS[terra_brand]['FILES'] + 
> user_total_files
>   LOCK.release()
> 
>   except Queue.Empty:
>   if EXIT:
>   break
>   else:
>   continue
>   except KeyboardInterrupt:
>   break
>   except Exception:
>   print mydir
>   raise
> 
> if len(sys.argv) < 2:
>   print 'Usage: %s dir...' % sys.argv[0]
>   sys.exit(1)
> 
> glob_dirs = []
> for i in sys.argv[1:]:
>   glob_dirs = glob_dirs + glob.glob(i+'/[a-z_]*')
> random.shuffle(glob_dirs)
> 
> for x in xrange(NRO_THREADS):
>   Worker().start()
> 
> try:
>   for i in glob_dirs:
>   POOL.put(i)
> 
>   EV.set()
>   while not POOL.empty():
>   time.sleep(1)
>   EXIT = True
> 
>   while (threading.activeCount() > 1):
>   time.sleep(1)
> except KeyboardInterrupt:
>   EXIT=True
> 
> for b in BRANDS:
>   print '%s:%i:%i:%i' % (b, BRANDS[b]['SIZE'], BRANDS[b]['COUNT'], 
> BRANDS[b]['FILES'])
> --code--
> 
> And run in make servers:
> 
> # uname -r
> 2.6.18-8.1.15.el5
> # python test.py /usr
> test:0:2267:0
> # python test.py /usr
> test:0:2224:0
> # python test.py /usr
> test:0:2380:0
> # python -V
> Python 2.4.3
> 
> # uname -r
> 7.0-BETA2
> # python test.py /usr
> test:0:1706:0
> # python test.py /usr
> test:0:1492:0
> # python test.py /usr
> test:0:1524:0
> # python -V
> Python 2.5.1
> 
> # uname -r
> 2.6.9-42.0.8.ELsmp
> # python test.py /usr
> test:0:1311:0
> # python test.py /usr
> test:0:1486:0
> # python test.py /usr
> test:0:1520:0
> # python -V
> Python 2.3.4
> 
> I really don't know what's happen.
> 
> Another ideia?
> 
> Regards
> 
> Chris Mellon wrote:
>> On Nov 13, 2007 1:06 PM, Marcus Alves Grando <[EMAIL PROTECTED]> wrote:
>>> Diez B. Roggisch wrote: