Re: A useful, but painful, one-liner to edit money amounts

2010-08-04 Thread Peter Otten
John Nagle wrote:

> There's got to be a better way to do this:
> 
> 
> def editmoney(n) :
>  return((",".join(reduce(lambda lst, item : (lst + [item]) if
>  item else lst,
>  re.split(r'(\d\d\d)',str(n)[::-1]),[])))[::-1])
> 
> 
>  >>> editmoney(0)
> '0'
>  >>> editmoney(13535)
> '13,535'
>  >>> editmoney(-14535)
> '-14,535'
>  >>> editmoney(123456)
> '123,456'
>  >>> editmoney(1234567890)
> '1,234,567,890'
>  >>> editmoney(-1234)
> '-1,234'
> 
> The basic idea here is that we want to split the string of digits
> into groups of 3 digits, aligned at the right.  Because regular
> expressions are right to left, we have to reverse the string to
> do that, then reverse again at the end.  s[::-1} reverses an
> interable.
> 
> "split" with a capturing group introduces empty strings into the
> list.  Hence the "reduce" and lambda to get rid of them.
> 
> Any better ideas?
> 
> (Yes, I know there's a built-in feature for this scheduled for
> Python 2.7.)


>>> locale.setlocale(locale.LC_ALL, ("en_US", "UTF-8"))
'en_US.UTF8'
>>> print locale.currency(13535, grouping=True)
$13,535.00
>>> print locale.format("%d", 13535, grouping=True)
13,535

>>> locale.setlocale(locale.LC_ALL, "")
'de_DE.UTF-8'
>>> print locale.currency(13535, grouping=True)
13.535,00 €
>>> print locale.format("%d", 13535, grouping=True)
13.535

Peter

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


Re: newbie problem with str.replace

2010-08-04 Thread Daniel da Silva
Also,
   for bestandsnaam in dirs and files:
is probably not doing what you want. Use + to concatenate  lists.


Daniel


On Wed, Aug 4, 2010 at 6:30 AM, Mike Kent  wrote:

> On Aug 4, 9:10 am, BobAalsma  wrote:
> > I'm working on a set of scripts and I can't get a replace to work in
> > the script - please help.
>
> >
> bestandsnaam_nieuw.replace(KLANTNAAM_OUT,KLANTNAAM_IN)
>
> I'm not sure what you are intending to do here, but string.replace
> does not do its replacement in-place.  It returns a copy of the
> original string, with the replacement done in the copy.  You are not
> assigning the string returned by string.replace to anything,
> therefore, it is immediately thrown away.
>
> Secondly, and this is just a guess, but since you are doing the
> string.replace inside of an os.walk loop, you appear to be trying to
> do a filename change.  I hope you realize that this will in no way
> change the name of the file *on disk*; it will only change it in
> memory.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A useful, but painful, one-liner to edit money amounts

2010-08-04 Thread Steven D'Aprano
On Wed, 04 Aug 2010 21:33:31 -0700, John Nagle wrote:

> There's got to be a better way to do this:
> 
> 
> def editmoney(n) :
>  return((",".join(reduce(lambda lst, item : (lst + [item]) if
>  item else lst,
>  re.split(r'(\d\d\d)',str(n)[::-1]),[])))[::-1])

What does the name "editmoney" mean? 

Why the obfuscated one-liner? It's not like you're using it in-line, 
you're putting it in a function, so who cares if it's one line or twenty?

def group_digits(n, size=3, sep=','):
"""Group int n in groups of size digits separated by sep."""
s = str(n)
m = len(s) % size
head = s[0:m]
tail = s[m:]
groups = [tail[i*size:(i+1)*size] for i in range(len(tail)//size)]
tail = sep.join(groups)
if head and tail:
return head + sep + tail
elif tail:
return tail
else:
return head


>>> group_digits(0)
'0'
>>> group_digits(1234567890)
'1,234,567,890'
>>> group_digits(1234567890, 4, ';')
'12;3456;7890'


Additional error checking, a better docstring, and extending it to 
support negative numbers is left as an exercise.



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


Re: A useful, but painful, one-liner to edit money amounts

2010-08-04 Thread Paul Rubin
John Nagle  writes:
> def editmoney(n) :
> return((",".join(reduce(lambda lst, item : (lst + [item]) if
> item else lst,
> re.split(r'(\d\d\d)',str(n)[::-1]),[])))[::-1])

Too obscure.  I usually use something like this:

def editmoney(n):
if n < 0: return '-' + editmoney(-n)
if n >= 1000:
return editmoney(n // 1000) + ',%03d'% (n % 1000)
return '%d'% n
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: simple (I hope!) problem

2010-08-04 Thread samwyse
On Aug 3, 1:20 am, Steven D'Aprano  wrote:
> On Mon, 02 Aug 2010 17:19:46 -0700, samwyse wrote:
> > Fortunately, I don't need the functionality of the object, I just want
> > something that won't generate an error when I use it.  So, what is the
> > quickest way to to create such an object (replacing the 'pass' in my
> > first snippet).  My solution is this:
>
> >     class C:
> >         def filter(self, *args, **kwds):
> >             pass
> >     register = C()
>
> > but it seems like I should be able to do something "better", as measured
> > by lines of code, faking more than just a 'filter' method, or both.  Any
> > ideas?  Thanks!
>
> You want a variation on the Null Object design pattern.
>
> class NullWithMethods(object):
>     def __getattr__(self, name):
>         return self
>     def __call__(self, *args, **kwargs):
>         pass
>
> And in action:
>
> >>> c = NullWithMethods()
> >>> c.spam("hello", "world")
> >>> c.something_completely_unlikely.spam.ham("hello", "world", foo=42)
>
> --
> Steven

JM emailed me a good solution, but yours is great! Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


A useful, but painful, one-liner to edit money amounts

2010-08-04 Thread John Nagle

There's got to be a better way to do this:


def editmoney(n) :
return((",".join(reduce(lambda lst, item : (lst + [item]) if
item else lst,
re.split(r'(\d\d\d)',str(n)[::-1]),[])))[::-1])


>>> editmoney(0)
'0'
>>> editmoney(13535)
'13,535'
>>> editmoney(-14535)
'-14,535'
>>> editmoney(123456)
'123,456'
>>> editmoney(1234567890)
'1,234,567,890'
>>> editmoney(-1234)
'-1,234'

The basic idea here is that we want to split the string of digits
into groups of 3 digits, aligned at the right.  Because regular
expressions are right to left, we have to reverse the string to
do that, then reverse again at the end.  s[::-1} reverses an
interable.

"split" with a capturing group introduces empty strings into the
list.  Hence the "reduce" and lambda to get rid of them.

Any better ideas?

(Yes, I know there's a built-in feature for this scheduled for
Python 2.7.)

John Nagle


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


100% without investment online part time jobs..(adsense, datawork, neobux..more jobs)

2010-08-04 Thread rosy us
100% without investment….no registration fee…no need money…
Online part time jobs…(googleadsense, dataentry…etc)all type of jobs…
 work from home..daily 2-3 hours…earn more money without any risk..


Full details at http://adsensejobworkfulldetails.co.cc/


More adsense tips,secrets,increasing money ,seo..also available…
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __init__ as a lambda

2010-08-04 Thread Steven D'Aprano
On Wed, 04 Aug 2010 12:58:18 -0700, Eric J. Van der Velden wrote:

> Hello,
> 
> Suppose
> 
> class C:
>  def __init__(self,name):self.name=name
> 
> I was wondering if I could make the __init__ a lambda function,

Of course you can. Lambdas aren't special types of functions, they are 
*syntax* for creating a function consisting of a single expression, and 
your __init__ function is a single expression.

These two are almost identical:

def spam(a, b):
return a+b


spam = lambda a, b: a+b

The only(?) differences are spam.func_name or spam.__name__.


> but
> 
> class C:
>  __init__=lambda self,self.name:None
> 
> and then later,
> 
> C('Hello')
> 
> does not work; the first argument, self, is assigned all rigth, but you
> cannot write the second argument with a dot,  self.name . 

That gives a syntax error no matter whether you use it in a lambda form 
or an ordinary function:

>>> def f(self,self.name):
  File "", line 1
def f(self,self.name):
   ^
SyntaxError: invalid syntax


So the problem has nothing to do with lambda. What you want is:

lambda self: self.name = None

but of course that doesn't work either, because self.name = None is not 
an expression, it's a statement. So:


class C:
__init__ = lambda self: setattr(self, 'name', None)


But don't do this. Seriously. Just because it is syntactically valid and 
does what you want, doesn't mean you should do it. Unless you have really 
good reason, and saving a single line of source code is a *bad* reason, 
just stick to the standard idiom that everyone can read without going 
"WTF is this guy doing this for???".

class C:
def __init__(self):
self.name = None




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


Re: Why is python not written in C++ ?

2010-08-04 Thread Roy Smith
In article ,
 Lawrence D'Oliveiro  wrote:

> In message , Grant Edwards wrote:
> 
> > The problem has nothing to do with the relative merits of the
> > languages.  The problem is inertia.
> 
> So how was C++ able to get popular in the first place? And how was Java able 
> to grab some share from it?

C++, for all its flaws, had one powerful feature which made it very 
popular.  It is a superset of C.  Whatever that may mean from a 
technical standpoint, it made the language feel safe and comfortable and 
low-risk to managers.  From a more technical standpoint, it had the very 
real advantage of being able to include all the C system headers and 
link against C system libraries.

As for Java, that's easy.  You could launch Java applets from inside a 
web browser.  In those days, anything related to the web was a one-way 
express ticket to fame and fortune.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is there no platform independent way of clearing a terminal?

2010-08-04 Thread David Robinow
On Wed, Aug 4, 2010 at 6:47 PM, Lawrence D'Oliveiro
 wrote:
> In message , David
> Robinow wrote:
>
>>  As an admittedly stupid comparison, I have 1579 DLLs in my
>> \windows\system32 directory.
>> Some number of these have been upgraded by Windows Update.
>
> What about the ones that aren’t? How do you maintain those?
Lawrence, you've been asking a lot of off-topic questions about
Microsoft Windows. I think it's wonderful that you're so open to new
ideas, but suggest that you take it to a Windows group, where I'm sure
you'll get a friendly response.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is python not written in C++ ?

2010-08-04 Thread Carl Banks
On Aug 4, 4:23 pm, Paul Rubin  wrote:
> Java was also on the OO bandwagon of the 1990's, which
> translated into good marketing back then, but is part of the cause of
> the massive bureaucracy and bloat in the Java runtime environment.  C++
> seems to have made something of a comeback because of this, and Java now
> has generics patterned after C++'s.

When I first studied Java, my first impression of the language was
that it had a Prime Directive that, "other than single inheritance and
being kinda like C, don't do anything C++ did".

Not a bad policy, actually.  However, omitting generics was probably
the second worst thing about Java (the worst thing being the awful AWT
design).


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


Re: Why is python not written in C++ ?

2010-08-04 Thread Carl Banks
On Aug 4, 4:04 pm, Grant Edwards  wrote:
> On 2010-08-04, Lawrence D'Oliveiro  wrote:
>
> > In message , Grant Edwards wrote:
>
> >> The problem has nothing to do with the relative merits of the
> >> languages.  The problem is inertia.
>
> > So how was C++ able to get popular in the first place?
>
> Building on C's popularity helped.

AT&T + Money + C backward compatibility


> > And how was Java able to grab some share from it?
>
> Good question.  Both IBM and Sun put a lot of effort/money behind
> Java.

Sun + IBM + Money + 90s Web trinkets


Carl Banks

(haven't seen a Java applet in ages)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Package management

2010-08-04 Thread Lawrence D'Oliveiro
In message <87pqxy2aqd@benfinney.id.au>, Ben Finney wrote:

> Have you ever tried to make such a package and get it into Debian?

I have found it very easy to recreate the same steps used by the package 
maintainers. For instance, “apt-get source ” brings down the exact 
same source files used by the maintainer to build the package. Also, “apt-
get build-dep ” will make sure you have the right development tools 
installed to do the build. Then dpkg-buildpackage will build your own 
version of the package, in exactly the same way that the maintainers do it.

> The automation you speak of must be made and maintained by people, and
> they can only automate to the extent that the Distutils output allows.

They seem to manage it OK. Just for fun, I tried building the python-cairo 
package from source, and among the output that flew by was

   for i in 2.5 2.6; do \
  python$i-dbg ./setup.py build; \
done

So they have found a way to automate the package build using distutils, 
rather than bypassing it.

Also it manages to perform useful-looking checks like

dpkg-shlibdeps: warning: dependency on libpthread.so.0 could be avoided if 
"debian/python-cairo/usr/lib/pyshared/python2.6/cairo/_cairo.so 
debian/python-cairo/usr/lib/pyshared/python2.5/cairo/_cairo.so" were not 
uselessly linked against it (they use none of its symbols).

Oversight in the upstream build procedure, perhaps?

Anyway, now I have my own .deb files, ready for installation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Package management

2010-08-04 Thread Ben Finney
Lawrence D'Oliveiro  writes:

> In message <87aap44mc7.fsf...@benfinney.id.au>, Ben Finney wrote:
>
> > Sadly, Python's package management is rather lacking by these
> > standards. The Distutils legacy assumption of “package recipient,
> > system administrator, and end user are all the same person”, among
> > other design decisions, makes it unusually difficult to have the
> > necessary separation of concerns between OS packaging, system
> > administration, and end user.
>
> Doesn’t matter. I’m pretty sure Debian has a way of automatically
> turning a distutils build into a .deb package with all the right
> dependencies. :)

Your certainty is no comfort to those who have to do the work of
actually making those packages. Have you ever tried to make such a
package and get it into Debian?

The automation you speak of must be made and maintained by people, and
they can only automate to the extent that the Distutils output allows.
Have you spoken about this with the people who did that work, and what
did they say to give you your certainty? If not, on what do you base
your certainty?

-- 
 \  “Any sufficiently advanced bug is indistinguishable from a |
  `\  feature.” —Rich Kulawiec |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Struggling to convert a mysql datetime object to a python string of a different format

2010-08-04 Thread Νίκος
Okey, i have many hours now struggling to convert a mysql datetime
field that i retreive to a string of this format '%d %b, %H:%M'

I google a lot but couldnt found out how to format it being a string

Here si the code so far:

try:
cursor.execute( ''' SELECT host, hits, date FROM visitors WHERE 
page
= '%s' ORDER BY date DESC ''' % (page) )
except MySQLdb.Error:
print( "Error %d: %s" % (e.args[0], e.args[1]) )
else:
#display results
print ( ''' ( Επισκέπτης ) - ( Επισκέψεις )
- ( Ημερομηνία ) ''' )
print ( '' )

results = cursor.fetchall()

for row in results:
print ( '''  ''' )

for entry in row:
entry = datetime.datetime.strftime( entry, '%d 
%b, %H:%M' ) #!!!
this is wrong!
print ( '''  %s  ''' % entry )

sys.exit(0)

Apart from that i don't know how iam supposed to print it, because the
date string is the 3rd string in every row of the dataset.

Please help me out!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __init__ as a lambda

2010-08-04 Thread John Nagle

On 8/4/2010 12:58 PM, Eric J. Van der Velden wrote:

Hello,

Suppose

class C:
  def __init__(self,name):self.name=name

I was wondering if I could make the __init__ a lambda


Python is not a functional language.  Attempts to make
it one make it worse.

There's this mindset that loops are somehow "bad".
This leads to list comprehensions, multiline lambdas, more
elaborate generators, weird conditional expression
syntax, and related cruft.  Most of these features are of
marginal, if not negative, value.

   Unfortunately, some of them have gone into Python.

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


Re: Why is python not written in C++ ?

2010-08-04 Thread Paul Rubin
Lawrence D'Oliveiro  writes:
> So how was C++ able to get popular in the first place? And how was
> Java able to grab some share from it?

C++ made improvements over C that were necessary and welcome for
controlling the complexity of large programs, while remaining mostly
upward compatible with C.  Java abandoned C compatibility and added
memory safety and GC.  That got rid of legacy-related pain and improved
program reliability and eased debugging considerably, at some cost in
performance.  Java was also on the OO bandwagon of the 1990's, which
translated into good marketing back then, but is part of the cause of
the massive bureaucracy and bloat in the Java runtime environment.  C++
seems to have made something of a comeback because of this, and Java now
has generics patterned after C++'s.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to pretty-print Python dict with unicode?

2010-08-04 Thread Vlastimil Brom
2010/8/5 kj :
>
> Is there a simple way to get Python to pretty-print a dict whose
> values contain Unicode?  (Of course, the goal here is that these
> printed values are human-readable.)
>
> If I run the following simple script:
>
> from pprint import pprint
> x = u'\u6c17\u304c\u9055\u3046'
> print '{%s: %s}' % (u'x', x)
> print {u'x': x}
> pprint({u'x': x})
>
> The first print statement produces perfectly readable Japanese,
> but the remaining statements both produce the line
>
> {u'x': u'\u6c17\u304c\u9055\u3046'}
>
> I've tried everything I can think of (including a lot of crazy
> stuff) short of re-writing pprint from scratch (which I think would
> be faster than grokking it and hacking at it).
>
> Isn't there an easier way to do this?
>
> Thanks!
>
> ~K
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I am not sure it helps, others will probably offer more elegant suggestions,
but if the dict is one-dimensional (i.e. it doesn't contain any other
containers or mappings - dicts, lists etc., but only strings, numbers,
you can use a simple print with a string conversion in a loop or join
the dict to a single printable string.

Python 2.7 (r27:82525, Jul  4 2010, 09:01:59) [MSC v.1500 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> d = {1: u'\u6c17\u304c\u9055\u3046', 2: u'\u6c17\u304c\u9055\u3046', 3: 
>>> u'\u6c17\u304c\u9055\u3046', }
>>> for k, v in d.items(): print "%s: %s" % (k, v)

1: 気が違う
2: 気が違う
3: 気が違う
>>> for k, v in d.items(): print "%s: %s," % (k, v),

1: 気が違う, 2: 気が違う, 3: 気が違う,
>>>
>>> print "".join("%s: %s, " % (k, v) for k, v in d.iteritems())
1: 気が違う, 2: 気が違う, 3: 気が違う,
>>>

Or you can use python 3, where repr() behaves directly like you would
need (also for arbitrarily nested data structers, unlike the simple
approach above):

Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> d = {1: '\u6c17\u304c\u9055\u3046', 2: '\u6c17\u304c\u9055\u3046', 3: 
>>> '\u6c17\u304c\u9055\u3046', }
>>> d
{1: '気が違う', 2: '気が違う', 3: '気が違う'}
>>>

(It might be possible to replace the sys.stdout to use str() as needed
on python 2.x too, but I am not sure if it would be worth it.)

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


Re: how to pretty-print Python dict with unicode?

2010-08-04 Thread Benjamin Kaplan
On Wed, Aug 4, 2010 at 3:15 PM, kj  wrote:
>
>
>
> Is there a simple way to get Python to pretty-print a dict whose
> values contain Unicode?  (Of course, the goal here is that these
> printed values are human-readable.)
>
> If I run the following simple script:
>
> from pprint import pprint
> x = u'\u6c17\u304c\u9055\u3046'
> print '{%s: %s}' % (u'x', x)
> print {u'x': x}
> pprint({u'x': x})
>
> The first print statement produces perfectly readable Japaneuse,
> but the remaining statements both produce the line
>
> {u'x': u'\u6c17\u304c\u9055\u3046'}
>
> I've tried everything I can think of (including a lot of crazy
> stuff) short of re-writing pprint from scratch (which I think would
> be faster than grokking it and hacking at it).
>
> Isn't there an easier way to do this?
>
> Thanks!
>
> ~K

use Python 3? http://www.python.org/dev/peps/pep-3138/

Or just iterate over the items and print them out yourself. The reason
you see the escaped values is that str(dict()) calls repr on all the
items. If you convert them to strings using str instead of repr(), it
will work the way you want.
-- 
http://mail.python.org/mailman/listinfo/python-list


adding optionMenu items in code

2010-08-04 Thread Chris Hare

I have an option menu

self.w = OptionMenu(self.frameNewNet, self.variable, "one", "two", "three")

Is there a way to add items to this programmatically, i.e. using values from a 
database?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is python not written in C++ ?

2010-08-04 Thread Grant Edwards
On 2010-08-04, Lawrence D'Oliveiro  wrote:
> In message , Grant Edwards wrote:
>
>> The problem has nothing to do with the relative merits of the
>> languages.  The problem is inertia.
>
> So how was C++ able to get popular in the first place?

Building on C's popularity helped.

> And how was Java able to grab some share from it?

Good question.  Both IBM and Sun put a lot of effort/money behind
Java.

-- 
Grant

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


Re: __init__ as a lambda

2010-08-04 Thread Carl Banks
On Aug 4, 12:58 pm, "Eric J. Van der Velden"
 wrote:
> Hello,
>
> Suppose
>
> class C:
>  def __init__(self,name):self.name=name
>
> I was wondering if I could make the __init__ a lambda function, but
>
> class C:
>  __init__=lambda self,self.name:None
>
> and then later,
>
> C('Hello')
>
> does not work; the first argument, self, is assigned all rigth, but
> you cannot write the second argument with a dot,  self.name .
> Or can I somehow?


__init__=lambda self,name:setattr(self,'name',name)

However if you actually do this, you need to be smacked upside the
head.


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


Re: Why is python not written in C++ ?

2010-08-04 Thread Paul Rubin
Lawrence D'Oliveiro  writes:
> > The Ada 2012 Language Reference Manual is 860 pages ...
> Yeah, unfortunately the language was designed by a committee ...
> It seems apt to describe the resulting design as “bulletproof”, but 
> “elegant” or “concise” ... not so much.

I'd say the Ada standardizers went to a great deal of trouble to specify
and document stuff that other languages simply leave undefined, leaving
developers relying on implementation-specific behavior that's not part
of the standard.  Ada itself is not necessarily more complicated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Questions, newbies, and community (was: python terminology on classes)

2010-08-04 Thread Ben Finney
"Rhodri James"  writes:

> On Wed, 04 Aug 2010 19:28:48 +0100, Steve Ferg
>  wrote:
>
> >> Seriously, we can't keep doing your thinking for you. The answers
> >> to all your questions are section 9 of the tutorial.
> >
> > This is is just the kind of newbie-hostile smart-ass reply that we do
> > not want to see on comp.lang.python.
[…]

> With Peng Yu, we've been through that quite a lot.  It seemed time to
> be a little sharper in the hope that learning might emerge.

As someone who generally deplores sharp replies to newbies for the
negative effect on the community as a whole and on later newcomers in
particular: I have to agree with Rhodri here. This specific case has
reached a point where some sharpness is warranted, in my opinion.

Peng Yu, please take Rhodri's reply in a spirit of mentoring. You have
all the tools at your disposal and they have been pointed out to you
numerous times. When asking a question of others, please demonstrate
that you have exhausted the existing resources you clearly know you have
available to you.

-- 
 \  “What we usually pray to God is not that His will be done, but |
  `\   that He approve ours.” —Helga Bergold Gross |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Package management (was: Why is there no platform independent way of clearing a terminal?)

2010-08-04 Thread Lawrence D'Oliveiro
In message <87aap44mc7.fsf...@benfinney.id.au>, Ben Finney wrote:

> Sadly, Python's package management is rather lacking by these standards.
> The Distutils legacy assumption of “package recipient, system
> administrator, and end user are all the same person”, among other design
> decisions, makes it unusually difficult to have the necessary separation
> of concerns between OS packaging, system administration, and end user.

Doesn’t matter. I’m pretty sure Debian has a way of automatically turning a 
distutils build into a .deb package with all the right dependencies. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is there no platform independent way of clearing a terminal?

2010-08-04 Thread Lawrence D'Oliveiro
In message , David 
Robinow wrote:

>  As an admittedly stupid comparison, I have 1579 DLLs in my
> \windows\system32 directory.
> Some number of these have been upgraded by Windows Update.

What about the ones that aren’t? How do you maintain those?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is python not written in C++ ?

2010-08-04 Thread Lawrence D'Oliveiro
In message , Grant Edwards wrote:

> The problem has nothing to do with the relative merits of the
> languages.  The problem is inertia.

So how was C++ able to get popular in the first place? And how was Java able 
to grab some share from it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is python not written in C++ ?

2010-08-04 Thread Lawrence D'Oliveiro
In message , Grant Edwards wrote:

> In my experience, the hiring issue is "we're already behind schedule
> and short-handed, we don't have the time or resources to teach people
> a new language."

Most people seem to need tutorials or handholding of some sort. Look at the 
number of questions in this group which could be answered just by reading 
the reference manual.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __init__ as a lambda

2010-08-04 Thread Stefan Schwarzer
Hi Eric,

On 2010-08-04 21:58, Eric J. Van der Velden wrote:
> class C:
>  def __init__(self,name):self.name=name
> 
> I was wondering if I could make the __init__ a lambda function, but
> 
> class C:
>  __init__=lambda self,self.name:None
> 
> and then later,
> 
> C('Hello')
> 
> does not work; the first argument, self, is assigned all rigth, but
> you cannot write the second argument with a dot,  self.name .

The "problem" is that in a lambda function the part after
the colon has to be an expression. However, you have used
an assignment there which isn't an expression in Python but
a statement.

For example, you can use

f = lambda x: sys.stdout.write(str(x))

(sys.stdout.write(str(x)) is an expression)

but not

f = lambda x: print x

(print x  is a statement in Python versions < 3)

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


Re: python terminology on classes

2010-08-04 Thread Rhodri James
On Wed, 04 Aug 2010 19:28:48 +0100, Steve Ferg  
 wrote:



Seriously, we can't keep doing your thinking for you.  The answers
to all your questions are section 9 of the tutorial.


This is is just the kind of newbie-hostile smart-ass reply that we do
not want to see on comp.lang.python.

Let's try again:

I think that the answers to all your questions are section 9 of the
tutorial.
http://docs.python.org/py3k/tutorial/index.html

Why don't you take a look at it, and then come back again if you still
have questions.


With Peng Yu, we've been through that quite a lot.  It seemed time to
be a little sharper in the hope that learning might emerge.

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Python 2.6.6 release candidate 1 now available

2010-08-04 Thread Barry Warsaw
Hello fellow Pythoneers and Pythonistas,

The source tarballs and Windows installers for the first (and hopefully only)
Python 2.6.6 release candidate is now available:

http://www.python.org/download/releases/2.6.6/

As usual, we would love it if you could download, install, and test these with
your favorite projects and environments.  A truly impressive number of bug
have been fixed since Python 2.6.5, with the full NEWS file available here:

http://www.python.org/download/releases/2.6.6/NEWS.txt

Barring complications, we expect to release Python 2.6.6 final on August 16,
2010.

Please note that with the release of Python 2.7 final on July 3, 2010, and in
accordance with Python policy, Python 2.6.6 is the last scheduled bug fix
maintenance release of the 2.6 series.  Because of this, your testing of this
release candidate will help immensely.  We will of course continue to support
security fixes in Python 2.6 for quite some time.

My thanks go out to everyone who has helped contribute fixes great and small,
and much testing and bug tracker gardening for Python 2.6.6.  The excellent
folks on #python-dev are true Pythonic heros too.

Enjoy,
-Barry
(on behalf of the Python development community)


signature.asc
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode error

2010-08-04 Thread Aahz
In article ,
Nobody   wrote:
>
>Java's checked exception mechanism was based on real-world experience of
>the pitfalls of abstract types. And that experience was gained in
>environments where interface specifications were far more detailed than is
>the norm in the Python world.

There are a number of people who claim that checked exceptions are the
wrong answer:

http://www.mindview.net/Etc/Discussions/CheckedExceptions
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"Normal is what cuts off your sixth finger and your tail..."  --Siobhan
-- 
http://mail.python.org/mailman/listinfo/python-list


how to pretty-print Python dict with unicode?

2010-08-04 Thread kj



Is there a simple way to get Python to pretty-print a dict whose
values contain Unicode?  (Of course, the goal here is that these
printed values are human-readable.)

If I run the following simple script:

from pprint import pprint
x = u'\u6c17\u304c\u9055\u3046'
print '{%s: %s}' % (u'x', x)
print {u'x': x}
pprint({u'x': x})

The first print statement produces perfectly readable Japanese,
but the remaining statements both produce the line

{u'x': u'\u6c17\u304c\u9055\u3046'}

I've tried everything I can think of (including a lot of crazy
stuff) short of re-writing pprint from scratch (which I think would
be faster than grokking it and hacking at it).

Isn't there an easier way to do this?

Thanks!

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


scipy / stats : quantiles using sample weights from survey data

2010-08-04 Thread Christopher Barrington-Leigh
There is a function scipy.stats.mstats.mquantiles  that returns
quantiles for a vector of data.
But my data should not be uniformly weighted in an estimate of the
distribution, since they are from a survey and come with estimated
sampling weights based on the stratification used in sampling.

Is there a routine to calculate these quantiles taking into account
the survey weights?  I can find nothing, so maybe you have had the
same problem and written something.

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


Re: XML parsing: SAX/expat & yield

2010-08-04 Thread kj
In  Peter Otten <__pete...@web.de> writes:

>How about

>http://effbot.org/zone/element-iterparse.htm#incremental-parsing

Exactly!

Thanks!

~K

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


[ANN] Websourcebrowser 0.4a released

2010-08-04 Thread Stefan Schwarzer
Hello,

I'm happy to announce the release of Websourcebrowser 0.4a.

Websourcebrowser is a program intended to get a quick overview of a
project's source code. The program is controlled from a web browser
which displays a directory tree and a source code file side by side.

The homepage of the project is at

http://websourcebrowser.sschwarzer.net/

The download of version 0.4a is at

http://websourcebrowser.sschwarzer.net/download

*** Note that this is still an alpha release. ***

I use the program regularly to dive into new projects, but I consider
it in the alpha stage because it has been used and tested by only a
few other people than me.

On Windows, this version doesn't seem to work with IE 8.0 whereas
it works with Firefox 3.6.8.

I know the software could be improved a lot. For some ideas, look at

http://websourcebrowser.sschwarzer.net/trac/wiki/Ideas
http://websourcebrowser.sschwarzer.net/trac/browser/todo.txt

If I implement this alone, it'll probably take years, given that
Websourcebrowser is a spare time project (beside my other project,
ftputil). So it would be great to get more developers on board.

Of course, I'm thankful for feedback on the mailing list (subscription
required to avoid spam, sorry),

http://codespeak.net/mailman/listinfo/websourcebrowser

or via private e-mail. If you encounter problems, you may also file a
bug report at

http://websourcebrowser.sschwarzer.net/trac/newticket

*** You need to log in as user wsbuser with password wsb . ***

Stefan

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


Re: BundleBuilder Question

2010-08-04 Thread Ned Deily
In article <20100804200820.1ir1h.80013.r...@cdptpa-web19-z02>,
  wrote:

> I stumbled upon an article about bundlebuilder, so I was testing it a little. 
>  At first it wouldn't work and had this in the error:
> 
> IOError: [Errno 2] No such file or directory: 
> '/System/Library/Frameworks/Python.framework/Versions/2.6/Resources/English.lp
> roj'
> [...]

This was a bug that has been fixed in subsequent maintenance releases of 
Python 2.6.   See http://bugs.python.org/issue4937

-- 
 Ned Deily,
 n...@acm.org

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


A new syntax for writing tests

2010-08-04 Thread Jonathan Fine

Hi

I just discovered today a new syntax for writing tests.  The basic idea 
is to write a function that contains some statements, and run it via a 
decorator.  I wonder if anyone had seen this pattern before, and how you 
feel about it.  For myself, I quite like it.


Let's suppose we want to test this trivial (of course) class.
class Adder(object):

def __init__(self):
self.value = 0

def plus(self, delta):
self.value += delta

The test the class you need a runner.  In this case it is quite simple.

def runner(script, expect):
'''Create an adder, run script, expect value.'''

adder = Adder()
script(adder)
return adder.value

We can now create (and run if we wish) a test.  To do this we write

@testit(runner, 4)
def whatever(a):
'''Two plus two is four.'''

a.plus(2)
a.plus(2)

Depending on the exact value of the testit decorator (which in the end 
is up to you) we can store the test, or execute it immediately, or do 
something else.


The simplest implementation prints:
OK: Two plus two is four.
for this passing test, and
Fail: Two plus four is five.
  expect 5
  actual 6
for a test that fails.

Here is the testit decorator used to produce the above output:

def testit(runner, expect):
'''Test statements decorator.'''

def next(script):
actual = runner(script, expect)
if actual == expect:
print 'OK:', script.__doc__
else:
print 'Fail:', script.__doc__
print '  expect', expect
print '  actual', actual

return next


You can pick this code, for at least the next 30 days, at
http://dpaste.com/hold/225056/

For me the key benefit is that writing the test is really easy.  Here's 
a test I wrote earlier today.


@testit(runner, '')
def whatever(tb):
tb.start('a', {'att': 'value'})
tb.start('b')
tb.end('b')
tb.end('a')

If the test has a set-up and tear-down, this can be handled in the 
runner, as can the test script raising an expected or unexpected exception.


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


Re: None is negative?

2010-08-04 Thread Thomas Jollans
On 08/03/2010 10:17 PM, wheres pythonmonks wrote:
> I did the google search... I must be blind as I don't see any hits...
> 
> None is negative in Python?  (v2.6)
> 
> http://www.google.com/search?ie=UTF-8&q=%22none+is+negative%22+python
> 
 if None < -999.99: print "hi"
> 
> hi

> 
 if -999 > None: print "hi"
> 
> hi

> 
> Is there a way to have the comparison raise an exception?
> 
> W


Not only was it negative, it was, in fact:

>>> None < float('-Inf')
True


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


Re: running a piece of code at specific intervals?

2010-08-04 Thread Jesse Jaggars
On Wed, Aug 4, 2010 at 2:44 PM, Chris Hare  wrote:
> Don't say cron :
>
> I want to have a section of my code executed at 15 minute intervals.  I am 
> using Threading.timer, but it is causing a problem sinxe I am using sqlite3 
> and the thread support gives me an error, which aborts part of my code.
>
> So, is there an alternative to threading.timer?
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Take a look at sched. http://docs.python.org/library/sched.html
-- 
http://mail.python.org/mailman/listinfo/python-list


BundleBuilder Question

2010-08-04 Thread jyoung79
I stumbled upon an article about bundlebuilder, so I was testing it a little.  
At first it wouldn't work and had this in the error:

IOError: [Errno 2] No such file or directory: 
'/System/Library/Frameworks/Python.framework/Versions/2.6/Resources/English.lproj'

I'm currently running OS X 10.6 with python2.6 as the default (looks to be 64 
bit).  I followed that path and found that the 'English.lproj' directory was 
not there.  I admit I'm not sure what I'm doing, but I went to a 10.5 Leopard 
machine and found that Python2.5 had this 'English.lproj' directory so I copied 
it over to my Python2.6 on OS 10.6.  Bundlebuilder then successfully created a 
standalone app.

I'm just wondering if it's a good idea to copy that English.lproj directory 
from Python2.5 to Python2.6?  What exactly is this directory for?  Looks like 
it only contains a "InfoPlist.strings" file.

Thanks.

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


Re: running a piece of code at specific intervals?

2010-08-04 Thread Dave Angel

Chris Hare wrote:

Don't say cron :

I want to have a section of my code executed at 15 minute intervals.  I am 
using Threading.timer, but it is causing a problem sinxe I am using sqlite3 and 
the thread support gives me an error, which aborts part of my code.

So, is there an alternative to threading.timer?

  
Depends on how that "section of code" relates to the rest of your code.  
If it's independent of the rest, then you can use subprocess to launch a 
separate process.  That won't interfere with your main code.  But of 
course if your main code is blocked for 20 minutes, it'll never get to 
the part which should run the subprocess.


If your main code is running wxPython, you can set a timer, and just 
trigger an event like all the others.


But without knowing more about your two pieces of code, the only 
reliable answer is 'cron'.


DaveA

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


__init__ as a lambda

2010-08-04 Thread Eric J. Van der Velden
Hello,

Suppose

class C:
 def __init__(self,name):self.name=name

I was wondering if I could make the __init__ a lambda function, but

class C:
 __init__=lambda self,self.name:None

and then later,

C('Hello')

does not work; the first argument, self, is assigned all rigth, but
you cannot write the second argument with a dot,  self.name .
Or can I somehow?

Thanks,

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


running a piece of code at specific intervals?

2010-08-04 Thread Chris Hare
Don't say cron :

I want to have a section of my code executed at 15 minute intervals.  I am 
using Threading.timer, but it is causing a problem sinxe I am using sqlite3 and 
the thread support gives me an error, which aborts part of my code.

So, is there an alternative to threading.timer?


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


Re: The Application cannot locate win32ui.pyd (or Python) (126)

2010-08-04 Thread vsoler
On Aug 4, 7:52 pm, Alex Willmer  wrote:
> On Aug 4, 5:19 pm, vsoler  wrote:
>
>
>
> > On Aug 4, 5:41 pm, Alex Willmer  wrote:
>
> > > On Aug 4, 2:35 pm, vsoler  wrote:
>
> > > > Hi all,
>
> > > > I just installed python 3.1.2 where I used to have python 2.6.4. I'm
> > > > working on Win7.
>
> > > > The IDLE GUI works, but I get the following message when trying to
> > > > open *.py files written for py 2.6
>
> > > >         The Application cannot locate win32ui.pyd (or Python) (126)
>
> > > win32ui is part of the PyWin32 package. Most likely you have a version
> > > of PyWin32 for Python 2.6 installed, you should uninstall that and
> > > install PyWin32 for Python 3.1. Downloads are 
> > > athttp://sourceforge.net/projects/pywin32/files/
>
> > > You should do the same for any other third party packages that are
> > > installed.
>
> > > > Moreover, when I try to open an old *.py file, I sometimes get a
> > > > message saying that the file should be converted to UTF-8. What does
> > > > this mean?
>
> > > Those files contain non-ascii characters (e.g. £, €, æ). Non-ascii
> > > characters must be encoded when saved using and encoding. UTF-8 is one
> > > such encoding, and it was chosen as the default .py encoding for
> > > Python 3.x. Those files are probably in iso8859, cp432, or perhaps
> > > UTF-16 (aka UCS-2). You can save them in UTF-8 using your favourite
> > > text editor, or declare the encoding so Python 3 knows it. More info:
>
> > >http://www.joelonsoftware.com/articles/Unicode.htmlhttp://docs.python...
>
> > > > I'm also trying to use the 2to3 converter, but I cannot see where the
> > > > converted files are written to!
>
> > > I think 2to3 prints a diff of the file changes to the console. The -w
> > > command line option should modify files in place.
>
> > Thank you Alex for your detailes reply.
>
> > Before switching to Python 3.1.2 I removed all my Python 2.6 packages
> > (python, pywin32, numpy, wxpython). However, the removal was not
> > complete since some files could not be removed. Additionally, I still
> > see my C:\python26 directory which is suposed not to exist any longer.
>
> It probably contains one or two files the installers weren't aware of.
> E.g. a module you added manually, a log, a .pyc
>
> > I would not like to take a lot of your time, but, do you have any
> > hints as to what I should do to 'tune' my PC?
>
> Take a backup then either delete the Python26 directory, or rename it.
> Any problems, reverse the process.

Thank you very much Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python terminology on classes

2010-08-04 Thread Steve Ferg
> Seriously, we can't keep doing your thinking for you.  The answers
> to all your questions are section 9 of the tutorial.

This is is just the kind of newbie-hostile smart-ass reply that we do
not want to see on comp.lang.python.

Let's try again:

I think that the answers to all your questions are section 9 of the
tutorial.
http://docs.python.org/py3k/tutorial/index.html

Why don't you take a look at it, and then come back again if you still
have questions.



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


Re: Trying to set a cookie within a python script

2010-08-04 Thread donn

On 04/08/2010 20:09, Dotan Cohen wrote:

Don't forget that the Euro symbol is outside the Greek character set.

I could make some kind of economic joke here, but I'm also broke :D

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


Re: Trying to set a cookie within a python script

2010-08-04 Thread Dotan Cohen
On Wed, Aug 4, 2010 at 18:30, Dave Angel  wrote:
> Depends on how sure you are that your program will never need characters
> outside your greek character set. Remember Y2K?
>

Don't forget that the Euro symbol is outside the Greek character set.

-- 
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Application cannot locate win32ui.pyd (or Python) (126)

2010-08-04 Thread Alex Willmer
On Aug 4, 5:19 pm, vsoler  wrote:
> On Aug 4, 5:41 pm, Alex Willmer  wrote:
>
>
>
>
>
> > On Aug 4, 2:35 pm, vsoler  wrote:
>
> > > Hi all,
>
> > > I just installed python 3.1.2 where I used to have python 2.6.4. I'm
> > > working on Win7.
>
> > > The IDLE GUI works, but I get the following message when trying to
> > > open *.py files written for py 2.6
>
> > >         The Application cannot locate win32ui.pyd (or Python) (126)
>
> > win32ui is part of the PyWin32 package. Most likely you have a version
> > of PyWin32 for Python 2.6 installed, you should uninstall that and
> > install PyWin32 for Python 3.1. Downloads are 
> > athttp://sourceforge.net/projects/pywin32/files/
>
> > You should do the same for any other third party packages that are
> > installed.
>
> > > Moreover, when I try to open an old *.py file, I sometimes get a
> > > message saying that the file should be converted to UTF-8. What does
> > > this mean?
>
> > Those files contain non-ascii characters (e.g. £, €, æ). Non-ascii
> > characters must be encoded when saved using and encoding. UTF-8 is one
> > such encoding, and it was chosen as the default .py encoding for
> > Python 3.x. Those files are probably in iso8859, cp432, or perhaps
> > UTF-16 (aka UCS-2). You can save them in UTF-8 using your favourite
> > text editor, or declare the encoding so Python 3 knows it. More info:
>
> >http://www.joelonsoftware.com/articles/Unicode.htmlhttp://docs.python...
>
> > > I'm also trying to use the 2to3 converter, but I cannot see where the
> > > converted files are written to!
>
> > I think 2to3 prints a diff of the file changes to the console. The -w
> > command line option should modify files in place.
>
> Thank you Alex for your detailes reply.
>
> Before switching to Python 3.1.2 I removed all my Python 2.6 packages
> (python, pywin32, numpy, wxpython). However, the removal was not
> complete since some files could not be removed. Additionally, I still
> see my C:\python26 directory which is suposed not to exist any longer.

It probably contains one or two files the installers weren't aware of.
E.g. a module you added manually, a log, a .pyc

> I would not like to take a lot of your time, but, do you have any
> hints as to what I should do to 'tune' my PC?

Take a backup then either delete the Python26 directory, or rename it.
Any problems, reverse the process.

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


Re: XML parsing: SAX/expat & yield

2010-08-04 Thread Peter Otten
kj wrote:

> I want to write code that parses a file that is far bigger than
> the amount of memory I can count on.  Therefore, I want to stay as
> far away as possible from anything that produces a memory-resident
> DOM tree.
> 
> The top-level structure of this xml is very simple: it's just a
> very long list of "records".  All the complexity of the data is at
> the level of the individual records, but these records are tiny in
> size (relative to the size of the entire file).
> 
> So the ideal would be a "parser-iterator", which parses just enough
> of the file to "yield" (in the generator sense) the next record,
> thereby returning control to the caller; the caller can process
> the record, delete it from memory, and return control to the
> parser-iterator; once parser-iterator regains control, it repeats
> this sequence starting where it left off.

How about

http://effbot.org/zone/element-iterparse.htm#incremental-parsing

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


XML parsing: SAX/expat & yield

2010-08-04 Thread kj



I want to write code that parses a file that is far bigger than
the amount of memory I can count on.  Therefore, I want to stay as
far away as possible from anything that produces a memory-resident
DOM tree.

The top-level structure of this xml is very simple: it's just a
very long list of "records".  All the complexity of the data is at
the level of the individual records, but these records are tiny in
size (relative to the size of the entire file).

So the ideal would be a "parser-iterator", which parses just enough
of the file to "yield" (in the generator sense) the next record,
thereby returning control to the caller; the caller can process
the record, delete it from memory, and return control to the
parser-iterator; once parser-iterator regains control, it repeats
this sequence starting where it left off.

The problem, as I see it, is that SAX-type parsers like expat want
to do everything with callbacks, which is not readily compatible
with the generator paradigm I just described.

Is there a way to get an xml.parsers.expat parser (or any other
SAX-type parser) to stop at a particular point to yield a value?

The only approach I can think of is to have the appropriate parser
callbacks throw an exception wherever a yield would have been.
The exception-handling code would have the actual yield statement,
followed by code that restarts the parser where it left off.
Additional logic would be necessary to implement the piecemeal
reading of the input file into memory.

But I'm not very conversant with SAX parsers, and even less with
generators, so all this may be unnecessary, or way off.

Any other tricks/suggestions for turning a SAX parsers into a
generator, please let me know.

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


Re: parsing a c project

2010-08-04 Thread Eli Bendersky
On Wed, Aug 4, 2010 at 14:33, Aitor Garcia wrote:

> Hi,
>
> I need to know the memory locations of all variables in a C project
> including
> variables allocated inside structs.
>


Aitor, try the pycparser project (http://code.google.com/p/pycparser/) -
it's a complete ISO C parser in pure Python. It has been used for tasks
similar to this one (parsing of struct/union declarations for various
purposes).

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


problem adding a scrollbar to a text widget

2010-08-04 Thread Chris Hare
Here is my chunk of code.  I can't figure out what I am doing wrong to put my 
scrollbar on the right hand side of the text box.

from Tkinter import *

def showLogFile():
top = Toplevel()
f = Frame(top, bd=0, bg="Gray")
top.title = "netcomm log file"
f.grid()
sc = Scrollbar(top)
sc.grid()
t = Text(f, yscrollcommand = sc.set)
sc.config(command=t.yview)
t.insert(END,"This is a line of text")
t.config(height=20,width=80,bg="Gray")
button = Button(f, text="Dismiss", command=top.destroy, 
highlightbackground="Red")
t.grid()
button.grid()


showLogFile()
mainloop()

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


Re: The Application cannot locate win32ui.pyd (or Python) (126)

2010-08-04 Thread vsoler
On Aug 4, 5:41 pm, Alex Willmer  wrote:
> On Aug 4, 2:35 pm, vsoler  wrote:
>
> > Hi all,
>
> > I just installed python 3.1.2 where I used to have python 2.6.4. I'm
> > working on Win7.
>
> > The IDLE GUI works, but I get the following message when trying to
> > open *.py files written for py 2.6
>
> >         The Application cannot locate win32ui.pyd (or Python) (126)
>
> win32ui is part of the PyWin32 package. Most likely you have a version
> of PyWin32 for Python 2.6 installed, you should uninstall that and
> install PyWin32 for Python 3.1. Downloads are 
> athttp://sourceforge.net/projects/pywin32/files/
>
> You should do the same for any other third party packages that are
> installed.
>
> > Moreover, when I try to open an old *.py file, I sometimes get a
> > message saying that the file should be converted to UTF-8. What does
> > this mean?
>
> Those files contain non-ascii characters (e.g. £, €, æ). Non-ascii
> characters must be encoded when saved using and encoding. UTF-8 is one
> such encoding, and it was chosen as the default .py encoding for
> Python 3.x. Those files are probably in iso8859, cp432, or perhaps
> UTF-16 (aka UCS-2). You can save them in UTF-8 using your favourite
> text editor, or declare the encoding so Python 3 knows it. More info:
>
> http://www.joelonsoftware.com/articles/Unicode.htmlhttp://docs.python.org/howto/unicode
>
> > I'm also trying to use the 2to3 converter, but I cannot see where the
> > converted files are written to!
>
> I think 2to3 prints a diff of the file changes to the console. The -w
> command line option should modify files in place.

Thank you Alex for your detailes reply.

Before switching to Python 3.1.2 I removed all my Python 2.6 packages
(python, pywin32, numpy, wxpython). However, the removal was not
complete since some files could not be removed. Additionally, I still
see my C:\python26 directory which is suposed not to exist any longer.

If I go to the Control Panel, I cannot see any of the above suposedly
removed programs as pending of removal, so I really do not know what
more to do. I was even thinking of removing the C:\python26 directory
with the Supr key, but I always heard that it is not a good idea, the
Registry could become inconsistent. Additionally, I have not found in
my Win7 system nay utility for fixing it, should it become corrupt.

Perhaps my questions concern a bit more the Operating system (windows)
than they do python, but since I am fond of python and I definitely
would like to become somehow proficient at it, I would like to solve
the problem that I have.

I would not like to take a lot of your time, but, do you have any
hints as to what I should do to 'tune' my PC?

Thank you very much for your help.

Vicente Soler

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


Re: error: (113, 'Software caused connection abort')0

2010-08-04 Thread Aahz
In article ,
sarah   wrote:
>
> i face with this problem when i want to run this command on cygwin:
> python  httpd.py  8000  example-300-1k-rigid.py

Make sure the webclient service is running.  (May not have anything to do
with your problem, but it's something I had a problem with recently.)
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"Normal is what cuts off your sixth finger and your tail..."  --Siobhan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Application cannot locate win32ui.pyd (or Python) (126)

2010-08-04 Thread Alex Willmer
On Aug 4, 2:35 pm, vsoler  wrote:
> Hi all,
>
> I just installed python 3.1.2 where I used to have python 2.6.4. I'm
> working on Win7.
>
> The IDLE GUI works, but I get the following message when trying to
> open *.py files written for py 2.6
>
>         The Application cannot locate win32ui.pyd (or Python) (126)
>

win32ui is part of the PyWin32 package. Most likely you have a version
of PyWin32 for Python 2.6 installed, you should uninstall that and
install PyWin32 for Python 3.1. Downloads are at
http://sourceforge.net/projects/pywin32/files/

You should do the same for any other third party packages that are
installed.

> Moreover, when I try to open an old *.py file, I sometimes get a
> message saying that the file should be converted to UTF-8. What does
> this mean?

Those files contain non-ascii characters (e.g. £, €, æ). Non-ascii
characters must be encoded when saved using and encoding. UTF-8 is one
such encoding, and it was chosen as the default .py encoding for
Python 3.x. Those files are probably in iso8859, cp432, or perhaps
UTF-16 (aka UCS-2). You can save them in UTF-8 using your favourite
text editor, or declare the encoding so Python 3 knows it. More info:

http://www.joelonsoftware.com/articles/Unicode.html
http://docs.python.org/howto/unicode

> I'm also trying to use the 2to3 converter, but I cannot see where the
> converted files are written to!

I think 2to3 prints a diff of the file changes to the console. The -w
command line option should modify files in place.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Get name of file from directory into variable

2010-08-04 Thread Steven W. Orr
On 08/03/10 06:21, quoth loial:
> In a unix shell script I can do something like this to look in a
> directory and get the name of a file or files into a variable :
> 
> MYFILE=`ls /home/mydir/JOHN*.xml`
> 
> 
> Can I do this in one line in python?
> 

Sorry, but I just can't help myself.

Yeah, it's one shell line, but why the extra process, setup of pipes,
teardown, and all the rest when you can just say

MYFILE=/home/mydir/JOHN*.xml

After all, your way just starts a subshell which runs ls in a grandchild
process and creates a pipe to read back what the subshell writes. All the
subhell does is to run ls on what the shell globs. And without any options to
the ls command, you're just as well off by using echo instead of ls.

MYFILE=`echo /home/mydir/JOHN*.xml`

Since echo is probably a builtin, you'd be creating a child but no grandchild.

Other than that, the use of glob in python answers your question well (unless
someone wants to write up how to do it in python by use of the subprocess
module along with the glob module...)

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trying to set a cookie within a python script

2010-08-04 Thread Dave Angel



¯º¿Â wrote:

On 3 Αύγ, 21:00, Dave Angel  wrote:



  

A string is an object containing characters. A string literal is one of
the ways you create such an object. When you create it that way, you
need to make sure the compiler knows the correct encoding, by using the
encoding: line at beginning of file.




mymessage = "καλημέρα"   < string
mymessage = u"καλημέρα"  < string literal?

So, a string literal is one of the encodings i use to create a string
object?

  
No, both lines take a string literal, create an object, and bind a name 
to that object. In the first case, the object is a string, and in the 
second it's a unicode-string. But the literal is the stuff after the 
equals sign in both these cases.


Think about numbers for a moment. When you say
salary = 4.1

you've got a numeric literal that's three characters long, and a name 
that's six characters long. When the interpreter encounters this line, 
it builds an object of type float, whose value approximates 4.1, 
according to the language rules. It then binds the name salary to this 
object.



Can the encodign of a python script file be in iso-8859-7 which means
the file contents is saved to the hdd as greek-iso but the part of
this variabel value mymessage ="καλημέρα" is saved as utf-8 ot the
opposite?

  
A given file needs to have a single encoding, or you're in big trouble. 
So a script file is encoded by the text editor in a single encoding 
method, which is not saved to the file (except indirectly if you specify 
BOM). It's up to you to add a line to the beginning to tell Python how 
to decode the file. One decoding for one file.

have the file saved as utf-8 but one variuable value as greek
encoding?

  

Variables are not saved to source (script) files. Literals are in the file.

Encodings still give me headaches. I try to understand them as
different ways to store data in a media.

Tell me something. What encoding should i pick for my scripts knowing
that only contain english + greek chars??
iso-8859-7 or utf-8 and why?

  
Depends on how sure you are that your program will never need characters 
outside your greek character set. Remember Y2K?



Can i save the sting lets say "Νίκος" in different encodings and still
print out correctly in browser?

ascii =he standard english character set only, right?

  

The web server wraps a few characters before and after your html stream,
but it shouldn't touch the stream itself.



So the pythoon compiler using the cgi module is the one that is
producing the html output that immediately after send to the web
server, right?


  

For example if i say mymessage =καλημέρα" and the i say mymessage = u"καλημέρα" 
then the 1st one is a greek encoding variable while the
2nd its a utf-8 one?
  

No, the first is an 8 bit copy of whatever bytes your editor happened to
save.



But since mymessage =καλημέρα" is a string containing greek
characaters why the editor doesn't save it as such?

  
Because the editor is editing text, not python objects. It's job is 
solely to represent all your keystrokes in some consistent manner so 
that they can be interpreted later by some other program, possibly a 
compiler.

It reminds me of varibles an valeus where if you say

a = 5, a var becomes instantly an integer variable
while
a = 'hello' , become instantly a string variable


  

mymessage = u"καλημέρα"

creates an object that is *not* encoded.



Because it isn't saved by the editor yet? In what satet is this object
in before it gets encoded?
And it egts encoded the minute i tell the editor to save the file?

  
You're confusing timeframes here. Notepad++ doesn't know Python, and 
it's long gone by the time the compiler deals with that line. In 
Notepad++, there are no python objects, encoded or not.

Encoding is taking the unicode
stream and representing it as a stream of bytes, which may or may have
more bytes than the original has characters.




So this line mymessage = u"καλημέρα" what it does is tell the browser
thats when its time to save the whole file to save this string as
utf-8?

  
No idea what you mean. The browser isn't saving anything; it doesn't 
even get involved till after the python code has completed.

If yes, then if were to save the above string as greek encoding how
was i suppose to right it?

Also if u ise the 'coding line' in the beggining of the file is there
a need for using the u literal?

  
If you don't use the u literal, then don't even try to use utf-8. You'll 
find that strings have the wrong lengths, and therefore subscripts and 
formatting will sometimes fail in strange ways.

I personally haven't done any cookie code. If I were debugging this, I'd
factor out the multiple parts of that if statement, and find out which
one isn't true. From here I can't guess.



I did what you say and foudn out that both of the if condition parts
were always false thast why the if code blck never got executed.

And it is alwsy wrong because the cookie ne

Re: Why is python not written in C++ ?

2010-08-04 Thread Grant Edwards
On 2010-08-04, Neil Hodgson  wrote:
> Grant Edwards:
>
>> That said, the last time I looked the Ada spec was only something like
>> 100 pages long, so a case could be made that it won't take long to
>> learn.  I don't know how long the C++ language spec is, but I'm
>> betting it's closer to 1000 than 100.
>
>The Ada 2012 Language Reference Manual is 860 pages and the Ada 2005
> LRM was 790 pages. The annotated versions are even longer
> http://www.ada-auth.org/standards/ada12.html

Wow.  That's grown a lot over the years.  I used to have a paper copy,
(single-sided), and it was only about 1cm thick.  Ok, I guess that was
probably 20 years ago...

-- 
Grant Edwards   grant.b.edwardsYow! I wonder if I ought
  at   to tell them about my
  gmail.comPREVIOUS LIFE as a COMPLETE
   STRANGER?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is python not written in C++ ?

2010-08-04 Thread Grant Edwards
On 2010-08-04, Paul Rubin  wrote:

> I'm not sure what the hiring issue is.  I think anyone skilled in C++
> or Java can pick up Ada pretty easily.  It's mostly a subset of C++
> with different surface syntax.

In my experience, the hiring issue is "we're already behind schedule
and short-handed, we don't have the time or resources to teach people
a new language."

-- 
Grant Edwards   grant.b.edwardsYow! Did YOU find a
  at   DIGITAL WATCH in YOUR box
  gmail.comof VELVEETA?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is python not written in C++ ?

2010-08-04 Thread Grant Edwards
On 2010-08-04, Paul Rubin  wrote:
> Grant Edwards  writes:

>> The issue that would prevent its use where I work is the inability to
>> hire anybody who knows Ada.  ...
>> That said, the last time I looked the Ada spec was only something like
>> 100 pages long, so a case could be made that it won't take long to
>> learn. 
>
> Well, I don't know Ada (I've read about it but not written actual
> code), so maybe I shouldn't be the one saying this, but geez, it's
> another imperative, procedural language, like Algol or Pascal or even
> C.  Its type is much more serious than C's but shouldn't be a problem
> for anyone who uses C++ or Java generics.

I agree 100%.

> It also has a real module system unlike more commonly used languages,
> but 1) that part seems easy to understand; and 2) usually that's used
> for multi-programmer projects, so as long as there's some reasonable
> proportion of experienced users on the team, the inter-module
> interfaces should be sensible and less experienced users can just
> program to existing interfaces and/or get some help from others.
> Ada's module system is much simpler than (say) ML's.
>
>> I don't know how long the C++ language spec is, but I'm betting it's
>> closer to 1000 than 100. 
>
> I don't know about an official spec.  Stroustrup's "The C++
> programming language" is about 1000 pp, but it's a textbook, with
> lots of examples, exercises, etc.  I read through an earlier
> (shorter) edition in a couple of evenings a long time ago and it all
> made sense.  It has some hairy aspects like the notorious template
> metaprogramming, but most users simply won't get involved with that.
> Python has its own obscure and confusing features if that matters.

I couldn't get anybody to use Python either. :/

The problem has nothing to do with the relative merits of the
languages.  The problem is inertia.

> I think I'm a reasonably good Python programmer but I've never
> written a special metaclass and wouldn't really know how to.

-- 
Grant Edwards   grant.b.edwardsYow! I would like to
  at   urinate in an OVULAR,
  gmail.comporcelain pool --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: parsing a c project

2010-08-04 Thread Jon Clements
On 4 Aug, 12:33, Aitor Garcia  wrote:
> Hi,
>
> I need to know the memory locations of all variables in a C project including
> variables allocated inside structs.

Pray tell us why?

>
> What I want to do in to expand the structs into its basic elements (floats,
> int16 and int8).
>
> In a  header file (example.h) I have the following definitions.
>
> struct house{
>   float area;
>
>   int8 rooms;
>   int16 visits;
>
> };
>
> struct car{
>   float price;
>   int8 color;
>
> };
>
> I have been able to extract from the project the name of every struct, the 
> type of the struct and the beginning address of each struct.

How have you done this? What compiler and debugger/profiler are you
using? etc...
The memory address is going to possibly change every time, unless
you're talking static variables within an applications own address
space (even then I'm not 100% sure -- I haven't had to touch C in 2
years, so I'd declare myself rusty).

>
> example_list=[]
> example_list.append(['house1','struct house','82d0')
> example_list.append(['house2','struct house','3000')
> example_list.append(['car1','struct car','4000')
>
> I need an output like this.
>
> house1_struct_house_area float 82d0
> house1_struct_house_rooms int8 82d4
> house1_struct_house_visits int16 82d5
> house2_struct_house_area float 3000
> house2_struct_house_rooms int8 3004
> house2_struct_house_visits int16 3005
> car1_struct_car_price float 4000
> car1_struct_car_color int8 4004
>
> How can I efficiently do this in Python ?

Well using the pyparsing library, it's extremely easy to parse the C
grammar. But that's not what you're asking.

>
> I do not have very clear which element of Python should I use
> to store the struct list or class
>
> I would be very grateful if someone could give me some pointers.

An un-intended C pun :) ?

If you let the list know the use-case, then we might stand a chance of
giving you some reference (C++ pun?)

Jon.

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


The Application cannot locate win32ui.pyd (or Python) (126)

2010-08-04 Thread vsoler
Hi all,

I just installed python 3.1.2 where I used to have python 2.6.4. I'm
working on Win7.

The IDLE GUI works, but I get the following message when trying to
open *.py files written for py 2.6

The Application cannot locate win32ui.pyd (or Python) (126)

Should I change the PATH in Windows? Should I change the PYTHONPATH? I
am a bit lost. Everything worked fine with 2.6.

Moreover, when I try to open an old *.py file, I sometimes get a
message saying that the file should be converted to UTF-8. What does
this mean?

I'm also trying to use the 2to3 converter, but I cannot see where the
converted files are written to!

Any help is highly appreciated.

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


Re: newbie problem with str.replace

2010-08-04 Thread Mike Kent
On Aug 4, 9:10 am, BobAalsma  wrote:
> I'm working on a set of scripts and I can't get a replace to work in
> the script - please help.

>                         bestandsnaam_nieuw.replace(KLANTNAAM_OUT,KLANTNAAM_IN)

I'm not sure what you are intending to do here, but string.replace
does not do its replacement in-place.  It returns a copy of the
original string, with the replacement done in the copy.  You are not
assigning the string returned by string.replace to anything,
therefore, it is immediately thrown away.

Secondly, and this is just a guess, but since you are doing the
string.replace inside of an os.walk loop, you appear to be trying to
do a filename change.  I hope you realize that this will in no way
change the name of the file *on disk*; it will only change it in
memory.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie problem with str.replace

2010-08-04 Thread BobAalsma
On Aug 4, 3:22 pm, Anthony Tolle  wrote:
> On Aug 4, 9:10 am, BobAalsma  wrote:
>
> >                         #
> >                         bestandsnaam_nieuw = bestandsnaam
> >                         
> > bestandsnaam_nieuw.replace(KLANTNAAM_OUT,KLANTNAAM_IN)
>
> The replace method does not modify the string (strings are immutable).
>
> You need to use the retun value of the method in an assignment, like
> so:
>
> bestandsnaam_nieuw = bestandsnaam.replace(KLANTNAAM_OUT,KLANTNAAM_IN)
>
> This will not change the value of bestandsnaam

YESS!

Thanks, this is what I wanted to achieve but could not find

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


Re: newbie problem with str.replace

2010-08-04 Thread Peter Otten
BobAalsma wrote:

Although [it] may not be obvious at first unless you're Dutch...

> bestandsnaam_nieuw = bestandsnaam
> bestandsnaam_nieuw.replace(KLANTNAAM_OUT,KLANTNAAM_IN)

str.replace() does not modify a string, it creates a new one.

This doesn't work:
 
>>> s = "that's all folks"
>>> s.replace("all", "nothing")
"that's nothing folks"
>>> s
"that's all folks"

But this does:

>>> old = "that's all folks"
>>> new = old.replace("all", "nothing")
>>> new
"that's nothing folks"

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


Re: newbie problem with str.replace

2010-08-04 Thread Anthony Tolle
On Aug 4, 9:10 am, BobAalsma  wrote:
>                         #
>                         bestandsnaam_nieuw = bestandsnaam
>                         bestandsnaam_nieuw.replace(KLANTNAAM_OUT,KLANTNAAM_IN)

The replace method does not modify the string (strings are immutable).

You need to use the retun value of the method in an assignment, like
so:

bestandsnaam_nieuw = bestandsnaam.replace(KLANTNAAM_OUT,KLANTNAAM_IN)

This will not change the value of bestandsnaam
-- 
http://mail.python.org/mailman/listinfo/python-list


newbie problem with str.replace

2010-08-04 Thread BobAalsma
I'm working on a set of scripts and I can't get a replace to work in
the script - please help.

The scripts show no errors, work properly apart from the replace, all
variables are filled as expected, the scripts works properly when the
commands are copied to the Python shell.

Text Main:
..
from LeadDevice_klant_nieuw_bewerken_bestanden import omkattenBoom,
omkattenNaam
...
#
# (3) omkatten bestandsnamen:
#
print 'Omkatten bestandsnamen'
omkattenNaam(AANGRIJPINGSPUNT, KLANTNAAM_OUT, KLANTNAAM_IN,
ZOEKSET1_OUT, ZOEKSET1_IN, ZOEKSET2_OUT, ZOEKSET2_IN)
#



Text LeadDevice_klant_nieuw_bewerken_bestanden:
import os
import distutils.core

...

def omkattenNaam(AANGRIJPINGSPUNT, KLANTNAAM_OUT, KLANTNAAM_IN,
ZOEKSET1_OUT, ZOEKSET1_IN, ZOEKSET2_OUT, ZOEKSET2_IN):
#
# Strings opbouwen voordat aan de lussen gewerkt wordt:
#
beginpunt = AANGRIJPINGSPUNT + KLANTNAAM_IN + '/'
#
ZOEKSET1_OUT_LOWER = ZOEKSET1_OUT.lower()
ZOEKSET1_IN_LOWER = ZOEKSET1_IN.lower()
ZOEKSET2_OUT_LOWER = ZOEKSET2_OUT.lower()
ZOEKSET2_IN_LOWER = ZOEKSET2_IN.lower()
#
# Lussen:
#
for root, dirs, files in os.walk(beginpunt, topdown = False):
for bestandsnaam in dirs and files:
#
bestandsnaam_nieuw = bestandsnaam
bestandsnaam_nieuw.replace(KLANTNAAM_OUT,KLANTNAAM_IN)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python package to read .7z archives?

2010-08-04 Thread Hallvard B Furuseth
Giampaolo Rodolà  writes:
> 2010/8/4 Hallvard B Furuseth :
>> Is there an equivalent of zipfile.py for .7z archives?
>> I have one which extracts an archive member by running 7z e -so,
>> but that's a *slow* way to read one file at a time.
>>
>> Google found me some python interfaces to lzma, but apparently they
>> only handle single compressed files, not .7z archives.
>>
>> (Actually another archive format would be fine if it is competitive.
>> I'm just looking to compress my .zips better.  I need a Python module
>> to extract members reasonably fast, but slow compression would be OK.)
>
> http://bugs.python.org/issue5689

[For lzma/xz compressed tar archives]

Thanks, but extraction of individual members from .tar.xz looks
inherently slow.  To locate the member, you need to decompress
the entire portion of the archive preceding the member.

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


Re: lpr via subprocess in 2.4

2010-08-04 Thread James Mills
On Wed, Aug 4, 2010 at 9:38 PM, loial  wrote:
> I have also been trying to get the return code and standard error.

p = Popen("..., stderr=PIPE)

Look up the docs for subprocess.Popen

cheers
James

-- 
-- James Mills
--
-- "Problems are solved by method"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lpr via subprocess in 2.4

2010-08-04 Thread loial
Thanks...that worked.

I have also been trying to get the return code and standard error.

How do I access these?

#!/usr/bin/python
import os
import subprocess
process=subprocess.Popen(['lpr', '-P' ,'raserlpr','/etc/hosts'],
shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

print process.communicate()








On 4 Aug, 12:08, Peter Otten <__pete...@web.de> wrote:
> loial wrote:
> > I am am trying to run the following command via subprocess
>
> > lpr -P printqueue filetoprint
>
> > I cannot seem to get it to work and return stderr
>
> > I think the issue is how to specify the arguments
>
> > I am trying
>
> > subprocess.Popen(['lpr -P' ,'laserlpr','/etc/hosts'], shell=False)
>
> This looks for an executable called "lpr -P"; try
>
> subprocess.Popen(['lpr', '-P' ,'laserlpr','/etc/hosts'], shell=False)
>
>
>
> > but get error :
>
> > Traceback (most recent call last):
> >   File "testopen.py", line 6, in ?
> >     subprocess.Popen(['lpr -P' ,'laserlpr','/etc/hosts'], shell=False)
> >   File "/usr/python2.4/lib/python2.4/subprocess.py", line 558, in __in
> > it__
> >     errread, errwrite)
> >   File "/usr/python2.4/lib/python2.4/subprocess.py", line 991, in _exe
> > cute_child
> >     raise child_exception
> > OSError: [Errno 2] No such file or directory- Hide quoted text -
>
> - Show quoted text -

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


parsing a c project

2010-08-04 Thread Aitor Garcia
Hi,

I need to know the memory locations of all variables in a C project including
variables allocated inside structs.

What I want to do in to expand the structs into its basic elements (floats,
int16 and int8).


In a  header file (example.h) I have the following definitions.

struct house{
  float area;

  int8 rooms;
  int16 visits;
};
  

struct car{
  float price;
  int8 color;
};

I have been able to extract from the project the name of every struct, the type 
of the struct and the beginning address of each struct.


example_list=[]
example_list.append(['house1','struct house','82d0')
example_list.append(['house2','struct house','3000')
example_list.append(['car1','struct car','4000')

I need an output like this. 

house1_struct_house_area float 82d0
house1_struct_house_rooms int8 82d4
house1_struct_house_visits int16 82d5
house2_struct_house_area float 3000
house2_struct_house_rooms int8 3004
house2_struct_house_visits int16 3005
car1_struct_car_price float 4000
car1_struct_car_color int8 4004

How can I efficiently do this in Python ?

I do not have very clear which element of Python should I use
to store the struct list or class

I would be very grateful if someone could give me some pointers.

Aitor



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


Re: Python package to read .7z archives?

2010-08-04 Thread Giampaolo Rodolà
2010/8/4 Hallvard B Furuseth :
> Is there an equivalent of zipfile.py for .7z archives?
> I have one which extracts an archive member by running 7z e -so,
> but that's a *slow* way to read one file at a time.
>
> Google found me some python interfaces to lzma, but apparently they
> only handle single compressed files, not .7z archives.
>
> (Actually another archive format would be fine if it is competitive.
> I'm just looking to compress my .zips better.  I need a Python module
> to extract members reasonably fast, but slow compression would be OK.)
>
> --
> Hallvard
> --
> http://mail.python.org/mailman/listinfo/python-list
>

http://bugs.python.org/issue5689


--- Giampaolo
http://code.google.com/p/pyftpdlib/
http://code.google.com/p/psutil/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lpr via subprocess in 2.4

2010-08-04 Thread Peter Otten
loial wrote:

> I am am trying to run the following command via subprocess
> 
> lpr -P printqueue filetoprint
> 
> I cannot seem to get it to work and return stderr
> 
> I think the issue is how to specify the arguments
> 
> I am trying
> 
> subprocess.Popen(['lpr -P' ,'laserlpr','/etc/hosts'], shell=False)

This looks for an executable called "lpr -P"; try

subprocess.Popen(['lpr', '-P' ,'laserlpr','/etc/hosts'], shell=False)
 
> but get error :
> 
> Traceback (most recent call last):
>   File "testopen.py", line 6, in ?
> subprocess.Popen(['lpr -P' ,'laserlpr','/etc/hosts'], shell=False)
>   File "/usr/python2.4/lib/python2.4/subprocess.py", line 558, in __in
> it__
> errread, errwrite)
>   File "/usr/python2.4/lib/python2.4/subprocess.py", line 991, in _exe
> cute_child
> raise child_exception
> OSError: [Errno 2] No such file or directory

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


Python package to read .7z archives?

2010-08-04 Thread Hallvard B Furuseth
Is there an equivalent of zipfile.py for .7z archives?
I have one which extracts an archive member by running 7z e -so,
but that's a *slow* way to read one file at a time.

Google found me some python interfaces to lzma, but apparently they
only handle single compressed files, not .7z archives.

(Actually another archive format would be fine if it is competitive.
I'm just looking to compress my .zips better.  I need a Python module
to extract members reasonably fast, but slow compression would be OK.)

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


lpr via subprocess in 2.4

2010-08-04 Thread loial
I am am trying to run the following command via subprocess

lpr -P printqueue filetoprint

I cannot seem to get it to work and return stderr

I think the issue is how to specify the arguments

I am trying

subprocess.Popen(['lpr -P' ,'laserlpr','/etc/hosts'], shell=False)

but get error :

Traceback (most recent call last):
  File "testopen.py", line 6, in ?
subprocess.Popen(['lpr -P' ,'laserlpr','/etc/hosts'], shell=False)
  File "/usr/python2.4/lib/python2.4/subprocess.py", line 558, in __in
it__
errread, errwrite)
  File "/usr/python2.4/lib/python2.4/subprocess.py", line 991, in _exe
cute_child
raise child_exception
OSError: [Errno 2] No such file or directory

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


Re: Difference between queues and pipes in multiprocessing

2010-08-04 Thread James Mills
On Wed, Aug 4, 2010 at 7:20 PM, Navkirat Singh  wrote:
> I was wondering what are the differences between queues and pipes implemented 
> using multiprocessing python module. Am I correct if I say, in pipes, if 
> another process writes to one receiving end concurrently, then an error will 
> be raised and in queues the later processes data will just queued up?

basically a Queue is a syncronization primitive used to
share and pass data to and from parent/child processes.

A pipe is as the name suggests, a socket pair connected
end-to-end allowing for full-duplex communications.

cheers
James

-- 
-- James Mills
--
-- "Problems are solved by method"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trying to set a cookie within a python script

2010-08-04 Thread Steven D'Aprano
On Tue, 03 Aug 2010 20:08:46 -0700, Νίκος wrote:

> i tried in IDLE enviroment as well and for some reason even with a
> single number isnated of time() function the cookie is never set,
> because the print of
> 
print os.environ.get('HTTP_COOKIE')
> 
> result to
> 
> None


What happens if you open up a NEW xterm and do this?

echo $HTTP_COOKIE


Or, to put it another way... are you sure that the environment variable 
is actually being set?


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


Re: Python Script Cannot Write to Directory

2010-08-04 Thread Steven D'Aprano
On Tue, 03 Aug 2010 21:01:38 -0700, Chris Brauchli wrote:

> Hi,
> 
> I am writing a script that, at one point, copies a file from directory A
> to directory B. Directory B can only be written to by root, but the
> script is always called with sudo, so this shouldn't be an issue, but it
> is. I have tried using shutil.copy() and calling "sudo cp " with
> os.popen to no avail. I cannot get the script to copy a file to
> directory B.
[...]
> Any ideas why this is happening? If more information is needed or
> something isn't clear let me know. Thanks for helping.

Without seeing the traceback and the actual line of code that fails, and 
preferably the full set of permissions on the directory, we'd be 
guessing. Now, I love to play "debug the program by making wild guesses" 
with other people's code, but you might not like my suggestions :)



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


Re: Global variables problem

2010-08-04 Thread Jean-Michel Pichavant

Navkirat Singh wrote:


On 04-Aug-2010, at 9:46 AM, Daniel da Silva wrote:

Please post approximate code that actually works and displays the 
problem.


On Tue, Aug 3, 2010 at 9:00 PM, Navkirat Singh > wrote:


Hey guys,

I am using a multiprocessing program, where the new process is
supposed to change a variable in the main class that it branches
out from. This is somehow not working, following is an
approximate code. Would really appreciate any insight into this
matter:


var = {}

class Something():

   def set_var(self):
   global var
   var = somevalue

   def get_var(self):
   return var

   def newprocess(self):
   self.set_var()

   def do_multiprocessing(self):
   while true:
   self.get_var()
   new_process = process(target=newprocess)
   new_process.start()


I am really confused here !

Any help would be awesome : )

Regards,
Nav

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




This is a working code, streamlined, but it is where the problem is:

from multiprocessing import * 


dicts = 0
print('global ', dicts)

class WebServer():
def set_sessionInfo(self):
global dicts
dicts = dicts + 1
def get_sessionInfo(self):
return dicts

def handle_connection(self):
self.set_sessionInfo()
def serve_forever(self):
for x in range(10):
p = Process(target=self.handle_connection)
p.start()
print(self.get_sessionInfo())
ws = WebServer()
ws.serve_forever()
print(dicts)




"As mentioned above, when doing concurrent programming it is usually 
best to avoid using shared state as far as possible. This is 
particularly true when using multiple processes.


However, if you really do need to use some shared data then 
multiprocessing provides a couple of ways of doing so."


source :

http://docs.python.org/library/multiprocessing.html


Read it, everything is explained with examples, including how to 
properly solve your problem.
"When using multiple processes, one generally uses message passing for 
communication between processes and avoids having to use any 
synchronization primitives like locks."


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


Difference between queues and pipes in multiprocessing

2010-08-04 Thread Navkirat Singh
Hi, 

I was wondering what are the differences between queues and pipes implemented 
using multiprocessing python module. Am I correct if I say, in pipes, if 
another process writes to one receiving end concurrently, then an error will be 
raised and in queues the later processes data will just queued up?

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


Re: Why is python not written in C++ ?

2010-08-04 Thread Jean-Michel Pichavant

Carl Banks wrote:

On Aug 3, 7:07 pm, Paul Rubin  wrote:
  

Mozilla is fed up with C++ and seems to be working on its own language,
called Rust:

   http://lambda-the-ultimate.org/node/4009



That looks much better than Go.

It's like all the cool features of Go without the annoying polemics.
I'm starting to get the feeling one of these languages is going to hit
a sweet spot and turn C into the next Cobol.


Carl Banks
  

I hope you're right, for our children sanity :)

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


error: (113, 'Software caused connection abort')0

2010-08-04 Thread sarah
hi
 i face with this problem when i want to run this command on cygwin:
 python  httpd.py  8000  example-300-1k-rigid.py
Dfghfji12d52s35s2sswee9E

with this error :0
Exception happened during processing of request from ('127.0.0.1',
35868)
Traceback (most recent call last):
  File "/usr/local/lib/python2.5/SocketServer.py", line 222, in
handle_reque
self.process_request(request, client_address)
  File "/usr/local/lib/python2.5/SocketServer.py", line 241, in
process_requ
self.finish_request(request, client_address)
  File "/usr/local/lib/python2.5/SocketServer.py", line 254, in
finish_reque
self.RequestHandlerClass(request, client_address, self)
  File "/usr/local/lib/python2.5/SocketServer.py", line 522, in
__init__
self.handle()
  File "/usr/local/lib/python2.5/BaseHTTPServer.py", line 316, in
handle
self.handle_one_request()
  File "/usr/local/lib/python2.5/BaseHTTPServer.py", line 310, in
handle_one
uest
method()
  File "/usr/local/lib/python2.5/SimpleHTTPServer.py", line 46, in
do_GET
self.copyfile(f, self.wfile)
  File "/usr/local/lib/python2.5/SimpleHTTPServer.py", line 175, in
copyfile
shutil.copyfileobj(source, outputfile)
  File "/usr/local/lib/python2.5/shutil.py", line 29, in copyfileobj
fdst.write(buf)
  File "/usr/local/lib/python2.5/socket.py", line 274, in write
self.flush()
  File "/usr/local/lib/python2.5/socket.py", line 261, in flush
self._sock.sendall(buffer)
error: (104, 'Connection reset by peer')

please help me
i am hurry!1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is python not written in C++ ?

2010-08-04 Thread Lawrence D'Oliveiro
In message 
<7d95c0d3-718d-4958-9364-263c833f1...@i24g2000yqa.googlegroups.com>, 
sturlamolden wrote:

> This is unsafe, anyone who writes this in C++ should be flogged:

Only if they’re using exceptions. Otherwise, it’s fine.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Script Cannot Write to Directory

2010-08-04 Thread Matteo Landi
On Wed, Aug 4, 2010 at 9:27 AM, Chris Rebert  wrote:
> On Wed, Aug 4, 2010 at 12:21 AM, News123  wrote:
> 
>> 3.) try following python
>>
>> import os
>> print os.getcwd()
>> import shutil
>> shutil("YOUR_SOURCE_FILE_NAME","DESTINATION_DIRECTORY/DSTNTN_FILE_NAME")
>
> WTF; modules aren't callable. Typo?

I suppose he/she would have written:

shutil.copyfile("YOUR_SOURCE_FILE_NAME","DESTINATION_DIRECTORY/DSTNTN_FILE_NAME")

Cheers.

>
> Cheers,
> Chris
> --
> http://blog.rebertia.com
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Matteo Landi
http://www.matteolandi.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is python not written in C++ ?

2010-08-04 Thread Lawrence D'Oliveiro
In message , Nobody wrote:

> One feature which can't readily be implemented in C is the automatic
> clean-up side of the RAII idiom.

Use do-once blocks
.

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


Re: Why is python not written in C++ ?

2010-08-04 Thread Lawrence D'Oliveiro
In message , Neil 
Hodgson wrote:

>The Ada 2012 Language Reference Manual is 860 pages and the Ada 2005
> LRM was 790 pages. The annotated versions are even longer
> http://www.ada-auth.org/standards/ada12.html

Yeah, unfortunately the language was designed by a committee which was 
trying to meet a specification laid down by another committee set up by the 
US military.

It seems apt to describe the resulting design as “bulletproof”, but 
“elegant” or “concise” ... not so much.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Global variables problem

2010-08-04 Thread Matteo Landi
Usually, modify global variables in a multi-thread/multi-process
scenario is not the right to operate: you better re-implement your
solution in a way that the shared resource is either protected with
synchronized objects or accessed by a single thread/process (and in
this case,  it won't be a shared resource anymore).

Think about the the needs of the shared resources: in this extremely
simple example, you can see that the increment of the session number
could be done by the server before spawning the child, but obviously
this is not a real scenario.

If you can't give up with shared resources, I recommend you to create
a synchronized object owned by the server but shared with the children
(take a look at the args keywords of the Process constructor).

Regards.

On Wed, Aug 4, 2010 at 9:47 AM, Navkirat Singh  wrote:
>  : (
> False alarm, the earlier solution breaks multiprocessing. Whats happening
> here is the child needs to change a variable in the parent process, So I
> think I am looking at shared memory (maybe). Any suggestions?
> Regards,
> Nav
>
>
> On 04-Aug-2010, at 12:41 PM, Navkirat Singh wrote:
>
> Thanks a lot guys !!
> I solved the problem:
> In the lines:
>>>
>>> new_process = process(target=newprocess)
>>>                        new_process.start()
>
> The target=newprocess is pointing towards a variable, instead of a function.
> So, appending a () will make it goto that function, thereby changing the
> global variable : )
> Thanks,
> Nav
>
> On 04-Aug-2010, at 11:42 AM, Daniel da Silva wrote:
>
> Your problem lies somewhere in the use of the Process class, not with global
> variables.
>
> If you replace your "p = ..." and "p.start()" lines with a direct call to
> self.handle_connection(), your code works as expected. I don't know much
> about the multiprocessing module, so I can't really comment on what you're
> doing wrong, but I hope this points you in the right direction.
>
> Sorry I couldn't be of more help,
>
> Daniel
>
>
> On Tue, Aug 3, 2010 at 9:48 PM, Navkirat Singh  wrote:
>>
>> On 04-Aug-2010, at 9:46 AM, Daniel da Silva wrote:
>>
>> Please post approximate code that actually works and displays the problem.
>>
>> On Tue, Aug 3, 2010 at 9:00 PM, Navkirat Singh 
>> wrote:
>>>
>>> Hey guys,
>>>
>>> I am using a multiprocessing program, where the new process is supposed
>>> to change a variable in the main class that it branches out from. This is
>>> somehow not working, following is an approximate code. Would really
>>> appreciate any insight into this matter:
>>>
>>>
>>> var = {}
>>>
>>> class Something():
>>>
>>>        def set_var(self):
>>>                global var
>>>                var = somevalue
>>>
>>>        def get_var(self):
>>>                return var
>>>
>>>        def newprocess(self):
>>>                self.set_var()
>>>
>>>        def do_multiprocessing(self):
>>>                while true:
>>>                        self.get_var()
>>>                        new_process = process(target=newprocess)
>>>                        new_process.start()
>>>
>>>
>>> I am really confused here !
>>>
>>> Any help would be awesome : )
>>>
>>> Regards,
>>> Nav
>>>
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>
>>
>> This is a working code, streamlined, but it is where the problem is:
>> from multiprocessing import *
>> dicts = 0
>> print('global ', dicts)
>> class WebServer():
>> def set_sessionInfo(self):
>> global dicts
>> dicts = dicts + 1
>> def get_sessionInfo(self):
>> return dicts
>> def handle_connection(self):
>> self.set_sessionInfo()
>> def serve_forever(self):
>> for x in range(10):
>> p = Process(target=self.handle_connection)
>> p.start()
>> print(self.get_sessionInfo())
>> ws = WebServer()
>> ws.serve_forever()
>> print(dicts)
>>
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>



-- 
Matteo Landi
http://www.matteolandi.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trying to set a cookie within a python script

2010-08-04 Thread Dotan Cohen
2010/8/4 Νίκος :
> Encodings still give me headaches. I try to understand them as
> different ways to store data in a media.
>
> Tell me something. What encoding should i pick for my scripts knowing
> that only contain english + greek chars??
> iso-8859-7 or utf-8 and why?
>

Always use UTF-8, every modern system supports it, and it will let you
use any arbitrary character that you need, such as maybe a smiley or a
Euro sign. You will avoid headaches with databases and files and all
sorts of other things that you don't yet expect. Declare it in the
HTTP header, and in the HTML meta tag.

Trust me, I maintain gibberish.co.il which specializes in encoding
problems. Just use UTF-8 everywhere and you will save a lot of
headaches.


> Can i save the sting lets say "Νίκος" in different encodings and still
> print out correctly in browser?
>

No.


> ascii = the standard english character set only, right?
>

Pretty much, plus the numbers, some symbols, and a few nonprinting
characters. Read here:
http://en.wikipedia.org/wiki/Ascii


-- 
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Urrlib2 IncompleteRead error

2010-08-04 Thread Gabriel Genellina
On 27 jul, 11:00, dirknbr  wrote:

> I am running urllib2.request and get this response when I do the read.
> Any ideas what causes this?
>
> return response.read()
>   File "C:\Python26\lib\socket.py", line 329, in read
>     data = self._sock.recv(rbufsize)
>   File "C:\Python26\lib\httplib.py", line 518, in read
>     return self._read_chunked(amt)
>   File "C:\Python26\lib\httplib.py", line 561, in _read_chunked
>     raise IncompleteRead(''.join(value))
> IncompleteRead: IncompleteRead(3235 bytes read)

Looks like a server error; a chunked transfer encoding finished before
reaching the expected size.

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


Re: Global variables problem

2010-08-04 Thread Navkirat Singh
 : ( 

False alarm, the earlier solution breaks multiprocessing. Whats happening here 
is the child needs to change a variable in the parent process, So I think I am 
looking at shared memory (maybe). Any suggestions?

Regards,
Nav



On 04-Aug-2010, at 12:41 PM, Navkirat Singh wrote:

> Thanks a lot guys !!
> 
> I solved the problem:
> 
> In the lines:
> 
>>> new_process = process(target=newprocess)
>>>new_process.start()
> 
> 
> 
> The target=newprocess is pointing towards a variable, instead of a function. 
> So, appending a () will make it goto that function, thereby changing the 
> global variable : )
> 
> Thanks,
> Nav
> 
> 
> On 04-Aug-2010, at 11:42 AM, Daniel da Silva wrote:
> 
>> Your problem lies somewhere in the use of the Process class, not with global 
>> variables.
>> 
>> If you replace your "p = ..." and "p.start()" lines with a direct call to 
>> self.handle_connection(), your code works as expected. I don't know much 
>> about the multiprocessing module, so I can't really comment on what you're 
>> doing wrong, but I hope this points you in the right direction.
>> 
>> Sorry I couldn't be of more help,
>> 
>> Daniel
>> 
>> 
>> On Tue, Aug 3, 2010 at 9:48 PM, Navkirat Singh  wrote:
>> 
>> On 04-Aug-2010, at 9:46 AM, Daniel da Silva wrote:
>> 
>>> Please post approximate code that actually works and displays the problem. 
>>> 
>>> On Tue, Aug 3, 2010 at 9:00 PM, Navkirat Singh  wrote:
>>> Hey guys,
>>> 
>>> I am using a multiprocessing program, where the new process is supposed to 
>>> change a variable in the main class that it branches out from. This is 
>>> somehow not working, following is an approximate code. Would really 
>>> appreciate any insight into this matter:
>>> 
>>> 
>>> var = {}
>>> 
>>> class Something():
>>> 
>>>def set_var(self):
>>>global var
>>>var = somevalue
>>> 
>>>def get_var(self):
>>>return var
>>> 
>>>def newprocess(self):
>>>self.set_var()
>>> 
>>>def do_multiprocessing(self):
>>>while true:
>>>self.get_var()
>>>new_process = process(target=newprocess)
>>>new_process.start()
>>> 
>>> 
>>> I am really confused here !
>>> 
>>> Any help would be awesome : )
>>> 
>>> Regards,
>>> Nav
>>> 
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>> 
>> 
>> This is a working code, streamlined, but it is where the problem is:
>> 
>> from multiprocessing import * 
>> 
>> dicts = 0
>> print('global ', dicts)
>> 
>> class WebServer():
>>  
>>  def set_sessionInfo(self):
>>  global dicts
>>  dicts = dicts + 1
>>  
>>  def get_sessionInfo(self):
>>  return dicts
>> 
>>  def handle_connection(self):
>>  self.set_sessionInfo()
>>  
>>  def serve_forever(self):
>>  for x in range(10):
>>  p = Process(target=self.handle_connection)
>>  p.start()
>>  print(self.get_sessionInfo())
>>  
>> ws = WebServer()
>> ws.serve_forever()
>> print(dicts)
>> 
>> 
>> 
> 

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


Re: Python Script Cannot Write to Directory

2010-08-04 Thread Chris Rebert
On Wed, Aug 4, 2010 at 12:21 AM, News123  wrote:

> 3.) try following python
>
> import os
> print os.getcwd()
> import shutil
> shutil("YOUR_SOURCE_FILE_NAME","DESTINATION_DIRECTORY/DSTNTN_FILE_NAME")

WTF; modules aren't callable. Typo?

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Script Cannot Write to Directory

2010-08-04 Thread News123
On 08/04/2010 06:01 AM, Chris Brauchli wrote:
> Hi,
> 
> I am writing a script that, at one point, copies a file from directory
> A to directory B. Directory B can only be written to by root, but the
> script is always called with sudo, so this shouldn't be an issue, but
> it is. I have tried using shutil.copy() and calling "sudo cp " with
> os.popen to no avail. I cannot get the script to copy a file to
> directory B. The strange thing is if I run the python interpreter (as
> sudo) and type in shutil.copy it works. It also works if I try to copy
> the file to a less protected directory. It only happens when I try to
> copy a file to directory B from a python script.
> 
> Any ideas why this is happening? If more information is needed or
> something isn't clear let me know. Thanks for helping.
> 

a fiew suggestions suggestions:


1,) open a terminal window with sudo -s and make ALL of the following
tests from this window.

2.) tell use the exact permissions of your destination directory
ls -ld DESTINATION_DIRECTORY

3.) verify, whether the file you want to copy exists already in the
destination directory
ls -l DESTINATION_DIRECTORY/DSTNTN_FILE_NAME


3.) try following python

import os
print os.getcwd()
import shutil
shutil("YOUR_SOURCE_FILE_NAME","DESTINATION_DIRECTORY/DSTNTN_FILE_NAME")


4.) try the same from a shell window
cp YOUR_SOURCE_FILE_NAME DESTINATION_DIRECTORY/DSTNTN_FILE_NAME


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


Re: Global variables problem

2010-08-04 Thread Navkirat Singh
Thanks a lot guys !!

I solved the problem:

In the lines:

>> new_process = process(target=newprocess)
>>new_process.start()



The target=newprocess is pointing towards a variable, instead of a function. 
So, appending a () will make it goto that function, thereby changing the global 
variable : )

Thanks,
Nav


On 04-Aug-2010, at 11:42 AM, Daniel da Silva wrote:

> Your problem lies somewhere in the use of the Process class, not with global 
> variables.
> 
> If you replace your "p = ..." and "p.start()" lines with a direct call to 
> self.handle_connection(), your code works as expected. I don't know much 
> about the multiprocessing module, so I can't really comment on what you're 
> doing wrong, but I hope this points you in the right direction.
> 
> Sorry I couldn't be of more help,
> 
> Daniel
> 
> 
> On Tue, Aug 3, 2010 at 9:48 PM, Navkirat Singh  wrote:
> 
> On 04-Aug-2010, at 9:46 AM, Daniel da Silva wrote:
> 
>> Please post approximate code that actually works and displays the problem. 
>> 
>> On Tue, Aug 3, 2010 at 9:00 PM, Navkirat Singh  wrote:
>> Hey guys,
>> 
>> I am using a multiprocessing program, where the new process is supposed to 
>> change a variable in the main class that it branches out from. This is 
>> somehow not working, following is an approximate code. Would really 
>> appreciate any insight into this matter:
>> 
>> 
>> var = {}
>> 
>> class Something():
>> 
>>def set_var(self):
>>global var
>>var = somevalue
>> 
>>def get_var(self):
>>return var
>> 
>>def newprocess(self):
>>self.set_var()
>> 
>>def do_multiprocessing(self):
>>while true:
>>self.get_var()
>>new_process = process(target=newprocess)
>>new_process.start()
>> 
>> 
>> I am really confused here !
>> 
>> Any help would be awesome : )
>> 
>> Regards,
>> Nav
>> 
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>> 
> 
> This is a working code, streamlined, but it is where the problem is:
> 
> from multiprocessing import * 
> 
> dicts = 0
> print('global ', dicts)
> 
> class WebServer():
>   
>   def set_sessionInfo(self):
>   global dicts
>   dicts = dicts + 1
>   
>   def get_sessionInfo(self):
>   return dicts
> 
>   def handle_connection(self):
>   self.set_sessionInfo()
>   
>   def serve_forever(self):
>   for x in range(10):
>   p = Process(target=self.handle_connection)
>   p.start()
>   print(self.get_sessionInfo())
>   
> ws = WebServer()
> ws.serve_forever()
> print(dicts)
> 
> 
> 

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