class versions and object deserialization

2012-04-24 Thread J. Mwebaze
We have classes of this form classA version1, classA version2, classA
version3 .. etc. This is same class that has been modified. Each
"modification" creates a new version of a class. Each object has a version
attribute which refers to the version of the class from which it was
derived. egObjectA.version =1 # means it was derived from ClassA version1

Here is my problem. During object de-serializing, i would like to use the
specific version of the class that was used to used to make the object. For
example, if i am de-serializing object ObjectA withversion=3 then ClassA
version 3 should be used. Source code for all the different variations of
the classes is stored.

This looks getting the object first the get the class. Any idea on how to
approach this?

-- 
*Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze |
skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze

/* Life runs on code */*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why () is () and [] is [] work in other way?

2012-04-24 Thread Thomas Rachel

Am 24.04.2012 08:02 schrieb rusi:

On Apr 23, 9:34 am, Steven D'Aprano  wrote:


"is" is never ill-defined. "is" always, without exception, returns True
if the two operands are the same object, and False if they are not. This
is literally the simplest operator in Python.


Circular definition: In case you did not notice, 'is' and 'are' are
(or is it is?) the same verb.


Steven's definition tries not to define the "verb" "is", but it defines 
the meanung of the *operator* 'is'.


He says that 'a is b' iff a and be are *the same objects*. We don't need 
to define the verb "to be", but the target of the definition is the 
entity "object" and its identity.



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


Re: why () is () and [] is [] work in other way?

2012-04-24 Thread Kiuhnm

On 4/24/2012 8:02, rusi wrote:

On Apr 23, 9:34 am, Steven D'Aprano  wrote:


"is" is never ill-defined. "is" always, without exception, returns True
if the two operands are the same object, and False if they are not. This
is literally the simplest operator in Python.


Circular definition: In case you did not notice, 'is' and 'are' are
(or is it is?) the same verb.


Python is not English.
Double-quoted 'is' is a Python operator, while non-quoted 'is' and 'are' 
are forms of the English verb 'to be'. If you change the name of the 
operator or the language in which you define the operator, you'll 
realize that there's no real circularity in that definition.


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


finding a regular expression in a file

2012-04-24 Thread S.B
Hello friends.

Newb question here.
I'm trying to find an efficient way to "grep" a file with python.
The problem is that all the solutions I find on the web read a line at a time 
from the file with a "for line in" loop and check each line for the RE instead 
of sweeping through the entire file.
This looks terribly inefficient...

I can read the entire file like so:
open("/etc/passwd").read() 
and use that in an re.search - e.g:
re.search("root",open("/etc/passwd").read())
The above will work BUT it will not interpolate the "\n" as a newline and will 
just print the entire file as a long line.
So if I try to look for '^root' (line starting with root) instead of 'root' it 
will NOT work

any ideas on how to get around this?

Thanks.

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


Re: finding a regular expression in a file

2012-04-24 Thread Jussi Piitulainen
"S.B" writes:

> Hello friends.
> 
> Newb question here.
> I'm trying to find an efficient way to "grep" a file with python.
> The problem is that all the solutions I find on the web read a line
> at a time from the file with a "for line in" loop and check each
> line for the RE instead of sweeping through the entire file.
> This looks terribly inefficient...
> 
> I can read the entire file like so:
> open("/etc/passwd").read() 
> and use that in an re.search - e.g:
> re.search("root",open("/etc/passwd").read())
> The above will work BUT it will not interpolate the "\n" as a
> newline and will just print the entire file as a long line.
> So if I try to look for '^root' (line starting with root) instead of
> 'root' it will NOT work
> 
> any ideas on how to get around this?

Check MULTILINE mode in the documentation: ^ "Matches the start of the
string, and in MULTILINE mode also matches immediately after each
newline."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding a regular expression in a file

2012-04-24 Thread Kushal Kumaran
On Apr 24, 2012 6:32 PM, "S.B"  wrote:
>
> Hello friends.
>
> Newb question here.
> I'm trying to find an efficient way to "grep" a file with python.
> The problem is that all the solutions I find on the web read a line at a
time from the file with a "for line in" loop and check each line for the RE
instead of sweeping through the entire file.
> This looks terribly inefficient...
>
> I can read the entire file like so:
> open("/etc/passwd").read()
> and use that in an re.search - e.g:
> re.search("root",open("/etc/passwd").read())
> The above will work BUT it will not interpolate the "\n" as a newline and
will just print the entire file as a long line.
> So if I try to look for '^root' (line starting with root) instead of
'root' it will NOT work
>
> any ideas on how to get around this?
>

You want the re.MULTILINE flag.

http://docs.python.org/py3k/library/re.html#re.MULTILINE

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


Re: why () is () and [] is [] work in other way?

2012-04-24 Thread rusi
On Apr 24, 4:06 pm, Thomas Rachel  wrote:
> Am 24.04.2012 08:02 schrieb rusi:
>
> > On Apr 23, 9:34 am, Steven D'Aprano > +comp.lang.pyt...@pearwood.info>  wrote:
>
> >> "is" is never ill-defined. "is" always, without exception, returns True
> >> if the two operands are the same object, and False if they are not. This
> >> is literally the simplest operator in Python.
>
> > Circular definition: In case you did not notice, 'is' and 'are' are
> > (or is it is?) the same verb.
>
> Steven's definition tries not to define the "verb" "is", but it defines
> the meanung of the *operator* 'is'.
>
> He says that 'a is b' iff a and be are *the same objects*. We don't need
> to define the verb "to be", but the target of the definition is the
> entity "object" and its identity.

Identity, sameness, equality and the verb to be are all about the same
concept(s) and their definitions are *intrinsically* circular; see
http://plato.stanford.edu/entries/identity/#2

And the seeming simplicity of the circular definitions hide the actual
complexity of 'to be'
for python:  http://docs.python.org/reference/expressions.html#id26
(footnote 7)
for math/philosophy: 
http://www.math.harvard.edu/~mazur/preprints/when_is_one.pdf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why () is () and [] is [] work in other way?

2012-04-24 Thread Kiuhnm

On 4/24/2012 15:25, rusi wrote:

On Apr 24, 4:06 pm, Thomas Rachel  wrote:

Am 24.04.2012 08:02 schrieb rusi:


On Apr 23, 9:34 am, Steven D'Apranowrote:



"is" is never ill-defined. "is" always, without exception, returns True
if the two operands are the same object, and False if they are not. This
is literally the simplest operator in Python.



Circular definition: In case you did not notice, 'is' and 'are' are
(or is it is?) the same verb.


Steven's definition tries not to define the "verb" "is", but it defines
the meanung of the *operator* 'is'.

He says that 'a is b' iff a and be are *the same objects*. We don't need
to define the verb "to be", but the target of the definition is the
entity "object" and its identity.


Identity, sameness, equality and the verb to be are all about the same
concept(s) and their definitions are *intrinsically* circular; see
http://plato.stanford.edu/entries/identity/#2

And the seeming simplicity of the circular definitions hide the actual
complexity of 'to be'
for python:  http://docs.python.org/reference/expressions.html#id26
(footnote 7)
for math/philosophy: 
http://www.math.harvard.edu/~mazur/preprints/when_is_one.pdf


What you say is true in general, but not from an operational point of 
view, especially if we restrict the set of objects whose sameness or 
identity we want to check:

Let O be a set of tuples (id, data) where
  {(id, data1), (id, data2)} subset O => data1 = data2
Def. (id1, data1) and (id2, data2) in O are /the same/ iff id1 = id2.
Now, it's easy to find a bijection between O and the set of Python's 
objects which are in memory at any single point in time.


Anyway, you're being unnecessarily pedantic.

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


Re: class versions and object deserialization

2012-04-24 Thread Ian Kelly
On Tue, Apr 24, 2012 at 1:02 AM, J. Mwebaze  wrote:
> We have classes of this form classA version1, classA version2, classA
> version3 .. etc. This is same class that has been modified. Each
> "modification" creates a new version of a class. Each object has a version
> attribute which refers to the version of the class from which it was
> derived. egObjectA.version =1 # means it was derived from ClassA version1

Note that each object already has a __class__ attribute containing the
class it is an instance of, so unless you have special need of version
number metadata, it may not be necessary.

> Here is my problem. During object de-serializing, i would like to use the
> specific version of the class that was used to used to make the object. For
> example, if i am de-serializing object ObjectA withversion=3 then ClassA
> version 3 should be used. Source code for all the different variations of
> the classes is stored.

What serialization scheme are you using, and how are the classes
stored?  If you're using pickle and you keep them accessible from the
module they were defined in using the name they were defined with,
then you won't need to do anything special here -- pickle will look up
that name in that module and find the class.  If you're doing
something more creative, then you'll want to override the __reduce__
method in your classes to pass in a custom constructor that takes into
account the version number.
-- 
http://mail.python.org/mailman/listinfo/python-list


trying to use spec file

2012-04-24 Thread George Georgalis
Hi

I posted this yesterday to compiler-sig, but I'm not sure there is any
traffic there?

There is a rather complex spec file for making rpm of python
interpreter, but I'm only seeing doc on making rpm packages (ie
programs); and, the spec file has difficult errors.

Is anyone interested in the spec file issues, or maybe I should just
make a simple one from it?

-George

-- Forwarded message --
From: George Georgalis 
Date: Mon, Apr 23, 2012 at 6:18 PM
Subject: trying to use spec file
To: compiler-...@python.org


Hi - hope this list is still active.

I'd like to make an rpm of 2.7.3 with some path and release tweeks.
However the spec file from the main distribution doesn't work for me
and it has some numbers from the prior release at the top (2.6).

-rw-r--r-- 1 1000 1002 13549 Apr  9 16:07
./Python-2.7.3/Misc/RPM/python-2.7.spec

Is it maintained? I would love some help and I can provide further
details (strip stops with files not found); but first I'd like to
confirm this file is working out of the box, for anyone?

I'm invoking it with "rpmbuild -bb python-2.7.spec" and I have all the
stated dependancies installed. Is this a supported path, it might be
easier for me to just create a new spec file?

-George

--
George Georgalis, (415) 894-2710, http://www.galis.org/


-- 
George Georgalis, (415) 894-2710, http://www.galis.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: trying to use spec file

2012-04-24 Thread Ned Deily
In article 
,
 George Georgalis  wrote:

> I posted this yesterday to compiler-sig, but I'm not sure there is any
> traffic there?
> 
> There is a rather complex spec file for making rpm of python
> interpreter, but I'm only seeing doc on making rpm packages (ie
> programs); and, the spec file has difficult errors.
> 
> Is anyone interested in the spec file issues, or maybe I should just
> make a simple one from it?

I'm not sure why that spec file is still there.  From the hg log for the 
spec file, it appears that it gets updated "automatically" at each 
release, likely by a script used by the release managers.  But I'd be 
pretty surprised to find that anyone uses the spec files as released.  
The Python release process no longer produces RPMs (it looks like it did 
at some point in the distant past) so it would only be used downstream 
by third-party distributors who do but I'm guessing they have their own, 
more complex spec files that they maintain themselves.  You might want 
to open an issue on the bug tracker (bugs.python.org) or ask on the 
python-dev mailing list.

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

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


Re: from calendar import* doesn't import everything

2012-04-24 Thread Tim Chase

On 04/24/12 18:18, Rotwang wrote:

Sorry if this is a stupid question, but what is up with this:

  >>>  from calendar import*
  >>>  Calendar

Traceback (most recent call last):
File "", line 1, in
  Calendar
NameError: name 'Calendar' is not defined
  >>>  from calendar import Calendar
  >>>  Calendar



If you view the source, you can see that __all__ is declared 
without containing "Calendar" in it.  So when you do "from 
calendar import *", only the things that are in __all__ are exported.


Now the REASON why "Calendar" is absent from __all__ is a 
question for the developers of the module.  But at least that's 
why Python is masking it from you.


-tkc


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


Re: from calendar import* doesn't import everything

2012-04-24 Thread Kiuhnm
On 4/25/2012 1:18, Rotwang wrote:
> Sorry if this is a stupid question, but what is up with this:
> 
>  >>> from calendar import*
>  >>> Calendar
> 
> Traceback (most recent call last):
> File "", line 1, in 
> Calendar
> NameError: name 'Calendar' is not defined
>  >>> from calendar import Calendar
>  >>> Calendar
> 
> 
> ?

calendar.py defines __all__ this way:

__all__ = ["IllegalMonthError", "IllegalWeekdayError", "setfirstweekday",
   "firstweekday", "isleap", "leapdays", "weekday", "monthrange",
   "monthcalendar", "prmonth", "month", "prcal", "calendar",
   "timegm", "month_name", "month_abbr", "day_name", "day_abbr"]

Only those names are imported with '*'.

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


Re: from calendar import* doesn't import everything

2012-04-24 Thread Rotwang

On 25/04/2012 00:42, Kiuhnm wrote:

On 4/25/2012 1:18, Rotwang wrote:

Sorry if this is a stupid question, but what is up with this:

  >>>  from calendar import*
  >>>  Calendar

Traceback (most recent call last):
File "", line 1, in
Calendar
NameError: name 'Calendar' is not defined
  >>>  from calendar import Calendar
  >>>  Calendar


?


calendar.py defines __all__ this way:

__all__ = ["IllegalMonthError", "IllegalWeekdayError", "setfirstweekday",
"firstweekday", "isleap", "leapdays", "weekday", "monthrange",
"monthcalendar", "prmonth", "month", "prcal", "calendar",
"timegm", "month_name", "month_abbr", "day_name", "day_abbr"]

Only those names are imported with '*'.

Kiuhnm


Oh, I didn't realise modules could do that. Thanks.

Do you know what the rationale behind not including 'Calendar' is?

--
Hate music? Then you'll hate this:

http://tinyurl.com/psymix
--
http://mail.python.org/mailman/listinfo/python-list


Re: from calendar import* doesn't import everything

2012-04-24 Thread Justin Ezequiel
see
http://docs.python.org/tutorial/modules.html#importing-from-a-package
http://stackoverflow.com/questions/2187583/whats-the-python-all-module-level-variable-for

I know the 1st link is for importing from a package but the same
applies for modules
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: from calendar import* doesn't import everything

2012-04-24 Thread Kiuhnm

On 4/25/2012 1:54, Rotwang wrote:

On 25/04/2012 00:42, Kiuhnm wrote:

On 4/25/2012 1:18, Rotwang wrote:

Sorry if this is a stupid question, but what is up with this:

>>> from calendar import*
>>> Calendar

Traceback (most recent call last):
File "", line 1, in
Calendar
NameError: name 'Calendar' is not defined
>>> from calendar import Calendar
>>> Calendar


?


calendar.py defines __all__ this way:

__all__ = ["IllegalMonthError", "IllegalWeekdayError", "setfirstweekday",
"firstweekday", "isleap", "leapdays", "weekday", "monthrange",
"monthcalendar", "prmonth", "month", "prcal", "calendar",
"timegm", "month_name", "month_abbr", "day_name", "day_abbr"]

Only those names are imported with '*'.

Kiuhnm


Oh, I didn't realise modules could do that. Thanks.

Do you know what the rationale behind not including 'Calendar' is?


Let's see... at line 561 of calendar.py there's something suspicious:

--->
# Support for old module level interface
c = TextCalendar()

firstweekday = c.getfirstweekday

def setfirstweekday(firstweekday):
try:
firstweekday.__index__
except AttributeError:
raise IllegalWeekdayError(firstweekday)
if not MONDAY <= firstweekday <= SUNDAY:
raise IllegalWeekdayError(firstweekday)
c.firstweekday = firstweekday

monthcalendar = c.monthdayscalendar
prweek = c.prweek
week = c.formatweek
weekheader = c.formatweekheader
prmonth = c.prmonth
month = c.formatmonth
calendar = c.formatyear
prcal = c.pryear
<---

So, it seems that "from calendar import *" is reserved for the "old 
interface" (i.e. non-OO).


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


generate random numbers in a deterministic way

2012-04-24 Thread Jabba Laci
Hi,

I'm working with some sorting algorithms and I want to compare their
efficiency. One test fills a list with one million random integers,
which serves as input for the algorithms. However, if this list is
different each time I run the tests, the tests wouldn't be fair. At
the moment the selected sorting alg. can be specified with a switch
and only one alg. is tested each time.

So what I want is the following: fill the list with random numbers,
but when I re-execute the script, I want the same "random" numbers in
the same order. This way each sorting alg. would get the same input.

As a workaround, I made a generator that outputs a random list in a
file, and this list is read each time by the testing script. I just
wonder if there is a more elegant solution.

Thanks,

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


Re: generate random numbers in a deterministic way

2012-04-24 Thread Temia Eszteri
Assuming you're using the Python's random module, which works based on
the Mersenne Twister, you can preset the seed with
random.seed(hashable).

More details here:
http://docs.python.org/library/random.html#random.seed

~Temia

On Wed, 25 Apr 2012 07:51:18 +0200, you wrote:

>Hi,
>
>I'm working with some sorting algorithms and I want to compare their
>efficiency. One test fills a list with one million random integers,
>which serves as input for the algorithms. However, if this list is
>different each time I run the tests, the tests wouldn't be fair. At
>the moment the selected sorting alg. can be specified with a switch
>and only one alg. is tested each time.
>
>So what I want is the following: fill the list with random numbers,
>but when I re-execute the script, I want the same "random" numbers in
>the same order. This way each sorting alg. would get the same input.
>
>As a workaround, I made a generator that outputs a random list in a
>file, and this list is read each time by the testing script. I just
>wonder if there is a more elegant solution.
>
>Thanks,
>
>Laszlo
--
When on earth, do as the earthlings do.
-- 
http://mail.python.org/mailman/listinfo/python-list


Download now

2012-04-24 Thread lipoco...@yahoo.com
Download "Free Duplicate Remover v1.1 - 389 KB
Detect and Remove Duplicate Files on your computer. By this free tool,
you
can help your computer work FASTER by removing unnecessary files. All
you
need to do is install this tool & start it. You'll get a list of
redundant
files that you'll have the choice to delete.
OS: Windows Vista/XP

http://lipocodes.com/FreeDuplicateRemover
-- 
http://mail.python.org/mailman/listinfo/python-list


Same code cause the different result.

2012-04-24 Thread 叶佑群

Hi, all

   I have code as:

/pobj = subprocess.Popen (["smbpasswd", user], stdin 
=subprocess.PIPE)

password += "\n"
pobj.stdin.write (password)
pobj.stdin.write (password)/

the command smbpasswd will change the samba user's password, In 
shell this will run as below:


/[root@localhost ~]# smbpasswd mytest1
New SMB password:
Retype new SMB password:
[root@localhost ~]# /

but in python code, it always prompt to wait input the password, it 
is seems that pobj.stdin.write () doesn't work. It is anything wrong 
with my code? I have another block code that runs as expected:


/pobj = subprocess.Popen (["passwd", user], stdin = 
subprocess.PIPE)

password = password + "\n"
pobj.stdin.write (password)
pobj.stdin.write (password)/

It is so curious and I wonder why.It is the same result when 
substitute smbpasswd with pdbedit.
-- 
http://mail.python.org/mailman/listinfo/python-list