Wednesday, February 24, 2010

comp.lang.python - 25 new messages in 14 topics - digest

comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en

comp.lang.python@googlegroups.com

Today's topics:

* Is this secure? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/ffff2b290db4e811?hl=en
* MODULE FOR I, P FRAME - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/b7f6043c2bc81cab?hl=en
* Watch nude girls fucking and sucking the cocks. Girls shaving their pussies,
boys giving shots on the pussies and licking them. Also watch girls getting
fucked on a car roof, a girl banged by a gang of four members. At the end the
girl collect - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/383482155a809f2c?hl=en
* Use eval() safely? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/885bc48dabf073e6?hl=en
* Pure virtual functions in Python? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/4bd25966f9a57f3e?hl=en
* Why One Should Go for Online Tech Support - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/a2a4f580b58be652?hl=en
* while loop with the condition used in the body - 6 messages, 4 authors
http://groups.google.com/group/comp.lang.python/t/9f957eab956b0718?hl=en
* Signature-based Function Overloading in Python - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/7abc18970a1757e7?hl=en
* Why tarfile.TarFile.gzopen is not in the online documentation? - 1 messages,
1 author
http://groups.google.com/group/comp.lang.python/t/fc36204286592cee?hl=en
* Creating variables from dicts - 5 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/bb1797ffb6fc3bd7?hl=en
* "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "
hollywood sexiest scenes" "hollywood blue films" "hollywood movies free
download" on http://sexyandpretty-girls.blogspot.com/ - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/1f799075f05d91a2?hl=en
* scope of generators, class variables, resulting in global na - 2 messages, 2
authors
http://groups.google.com/group/comp.lang.python/t/b1ff4d23cb5ec32c?hl=en
* WANTED: Regular expressions for breaking TeX/LaTeX document into tokens - 1
messages, 1 author
http://groups.google.com/group/comp.lang.python/t/ef9f01798e857e5e?hl=en
* Fascism is coming to Internet - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/6635d24df3ece879?hl=en

==============================================================================
TOPIC: Is this secure?
http://groups.google.com/group/comp.lang.python/t/ffff2b290db4e811?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Feb 23 2010 11:58 pm
From: Paul Rubin


Steven D'Aprano <steven@REMOVE.THIS.cybersource.com.au> writes:
> Given a random six character password taken out of an alphabet of 52
> characters, it takes over nine billion attempts to brute force it.
> Reducing the alphabet by 50% cuts that down to less than 200 million. To
> make up for that loss of 1 bit of entropy, you need two extra characters
> in your password.

One extra character comes pretty close (within 1.3 bits). Even two
extra chars is probably (subjective) easier for a user to deal with than
a completely random mixture of upper/lower case. You don't get the
extra bit per character if that distribution is anything other than
random, of course.

For something like a web password (each guess takes a server hit), where
the resource guarded is not very valuable, 5 chars is probably enough
for most purposes. For something like an encryption key subject to
offline attacks, 6 mixed-case characters will barely slow a real
attacker down.

As before, my suggestion is still diceware. I've used random
alphanumerics in the past but they're too big a hassle, they have to be
written down, etc.

And of course, if you're doing something serious, use a hardware token.

==============================================================================
TOPIC: MODULE FOR I, P FRAME
http://groups.google.com/group/comp.lang.python/t/b7f6043c2bc81cab?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Feb 24 2010 12:28 am
From: DANNY


On Feb 24, 3:11 am, "Rhodri James" <rho...@wildebst.demon.co.uk>
wrote:
> On Tue, 23 Feb 2010 10:39:21 -0000, DANNY <danijel.gv...@gmail.com> wrote:
> > @James I am thinkinhg about effect of errors that are within the
> > sequence of P frames. Where the P frames have only the information
> > about the changes in previous frames, so that errors are present until
> > the next Iframe. So I would like to see how is this seen in different
> > GoP sized clips.
>
> Ah, I see.  What I'd suggest you do is to encode your video clip at  
> various GOP sizes (you'll want some quite extreme ones for comparison),  
> then write a little program that reads in the file byte by byte and  
> randomly corrupts the data as it goes through.  "tsplay" from the tstools  
> suite that I mentioned earlier will do that for you (because it was very  
> handy for testing the robustness of our decoders).  Then watch the results  
> using VLC or similar.
>
> My recollection is that when the image isn't static, P frames tend to have  
> enough intra-coded blocks that corrupted video data doesn't have as much  
> effect as you might think.  I've dealt with streams that had ten seconds  
> or more between I frames, and starting at a random spot (simulating  
> changing channel on your digital TV) builds up an intelligible (if  
> obviously wrong) image surprisingly quickly.
>
> PS: my first name is Rhodri, not James.  Don't worry, it catches a lot of  
> people out.
>
> --
> Rhodri James *-* Wildebeeste Herder to the Masses

Well for my simulation of errors I am thinking on using the WANem
(Wide Area Netwrok Emulator) which has a function to simulate dellay,
jitter etc.. http://wanem.sourceforge.net/
I have been downloading the clips from youtube and I surprisengly saw
that I frame occures after 300 frames(at 15fps-so that means after 20
seconds)! That was quite unusal for my perception of the purpose of I
frame, but then I figured out that (as you mentioned) P frames include
intra-coded blocks which hide the effect of the errors.

The goal of my project is to make a program which plays the corrupted
video after being out thru error concealment, and in case when errors
overcome some threshold error value the program doesn't paly any more
frames until the I frame occures and then I would figure out the
optimal threshold value for the different GoP sizes as well as
different content of the clip.

==============================================================================
TOPIC: Watch nude girls fucking and sucking the cocks. Girls shaving their
pussies, boys giving shots on the pussies and licking them. Also watch girls
getting fucked on a car roof, a girl banged by a gang of four members. At the
end the girl collect
http://groups.google.com/group/comp.lang.python/t/383482155a809f2c?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Feb 24 2010 12:58 am
From: hhuifhiu ijuihuh


Watch nude girls fucking and sucking the cocks. Girls shaving their
pussies, boys giving shots on

the pussies and licking them. Also watch girls getting fucked on a car
roof, a girl banged by a gang

of four members. At the end the girl collects sperms from all four
mens penis in her mouth and

swallows it.


http://sites.google.com/site/niceglamourz

http://sites.google.com/site/niceglamourz

http://sites.google.com/site/niceglamourz

==============================================================================
TOPIC: Use eval() safely?
http://groups.google.com/group/comp.lang.python/t/885bc48dabf073e6?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Feb 24 2010 1:11 am
From: Dieter Maurer


Steven D'Aprano <steven@REMOVE.THIS.cybersource.com.au> writes on 22 Feb 2010 06:07:05 GMT:
> ...
> It's *especially* not safe if you put nothing in the globals dict,
> because Python kindly rectifies that by putting the builtins into it:
>
> >>> eval("__builtins__.keys()", {}, {})
> ['IndexError', 'all', 'help', 'vars', ... 'OverflowError']
>
>
> >>> eval("globals()", {}, {})
> {'__builtins__': {...}}
> >>>
> >>> eval("globals()", {'__builtins__': None}, {})
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "<string>", line 1, in <module>
> NameError: name 'globals' is not defined
>
> So {'__builtins__': None} is safer than {}. Still not safe, exactly, but
> safer. Or at least you make the Black Hats work harder before they own
> your server :)

Using functionality introduced with the class/type homogenization,
it is quite easy to get access to the "file" type (even when "__builtins__"
is disabled). Having "file", arbitrary files can be read, written, destroyed...


Dieter

==============================================================================
TOPIC: Pure virtual functions in Python?
http://groups.google.com/group/comp.lang.python/t/4bd25966f9a57f3e?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Feb 24 2010 1:17 am
From: Jean-Michel Pichavant


Arnaud Delobelle wrote:
> lallous <elias.bachaalany@gmail.com> writes:
>
>
>> Hello
>>
>> How can I do something similar to pure virtual functions in C++ ?
>>
>> Let us consider this:
>>
>> class C1:
>>
>> # Pure virtual
>> def cb(self, param1, param2):
>> """
>> This is a callback
>>
>> @param param1: ...
>> @param param2: ...
>> """
>> raise NotImplementedError, "Implement me"
>>
>
> Why define it if it is virtual?
>

Slightly off topic but this is often useful when writing interfaces. You
can then properly document what should any subclass (interface
implemention) be doing.
The thing is that in case of virtual methods, you *do want* to raise the
notImplemented exceptions, meaning you've failed to implement all the
required methods.
Strange thing that the OP want to silently call nothing at all when
calling a virtual method, he looses all the benefits from a virtual design.
Anyway, I don't deal into code optimization, this is not healthy :-)

JM

==============================================================================
TOPIC: Why One Should Go for Online Tech Support
http://groups.google.com/group/comp.lang.python/t/a2a4f580b58be652?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Feb 24 2010 1:18 am
From: nandini


Being a computer user, you almost every day make calls to your local
technician to repair your day to day PC problems such as operating
system issues, computer security problem, browser & email issues,
network and peripheral support. But hardly have you got your computer
repaired right away and even if your computer gets repaired
immediately, you cannot be assured of the quality of service provided.

And most importantly, like every other machine, computers too need
regular maintenance but a local technician cannot promise for the
same. Apart from this, you would have to pay your tech support
provider for his every visit, which sums up a heavy amount; sometimes
going beyond the limitation of your budget.

At the point in time, you must consider availing an online tech
support service. Offered on onetime payment scheme, online tech
support services are provided by numerous companies all across the
globe. These companies hire eminent Microsoft certified engineers as
technicians, who offer best services within moments.

Including this, there are many more benefits of services offered by
online tech support providers, such as –

* An inclusive range of tech support services on much lower
prices.
* Complete maintenance of your computer
* A completely secured support
* Instant fix for your computer

For Further information please visit http://www.pccare247.com

==============================================================================
TOPIC: while loop with the condition used in the body
http://groups.google.com/group/comp.lang.python/t/9f957eab956b0718?hl=en
==============================================================================

== 1 of 6 ==
Date: Wed, Feb 24 2010 1:15 am
From: Ulrich Eckhardt


Hi!

I'm looking for a way to write code similar to this C code:

while(rq = get_request(..)) {
handle_request(rq);
}

Currently I'm doing

while True:
rq = get_request(...)
if not rq:
break
handle_request(rq)

in Python 2.6. Any suggestions how to rewrite that?

Uli

--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

== 2 of 6 ==
Date: Wed, Feb 24 2010 2:07 am
From: Arnaud Delobelle


Ulrich Eckhardt wrote:
> Hi!
>
> I'm looking for a way to write code similar to this C code:
>
> while(rq = get_request(..)) {
> handle_request(rq);
> }
>
> Currently I'm doing
>
> while True:
> rq = get_request(...)
> if not rq:
> break
> handle_request(rq)
>
> in Python 2.6. Any suggestions how to rewrite that?
>

This is the common idiom.

--
Arnaud


== 3 of 6 ==
Date: Wed, Feb 24 2010 2:21 am
From: Peter Otten <__peter__@web.de>


Ulrich Eckhardt wrote:

> I'm looking for a way to write code similar to this C code:
>
> while(rq = get_request(..)) {
> handle_request(rq);
> }
>
> Currently I'm doing
>
> while True:
> rq = get_request(...)
> if not rq:
> break
> handle_request(rq)
>
> in Python 2.6. Any suggestions how to rewrite that?

Assuming get_request(...) is called with the same arguments on each
iteration and uses None to signal that there is no more data:

from functools import partial

for rq in iter(partial(get_request, ...), None):
handle_request(rq)

Peter


== 4 of 6 ==
Date: Wed, Feb 24 2010 2:31 am
From: Duncan Booth


Peter Otten <__peter__@web.de> wrote:

> Ulrich Eckhardt wrote:
>
>> I'm looking for a way to write code similar to this C code:
>>
>> while(rq = get_request(..)) {
>> handle_request(rq);
>> }
>>
> Assuming get_request(...) is called with the same arguments on each
> iteration and uses None to signal that there is no more data:
>
> from functools import partial
>
> for rq in iter(partial(get_request, ...), None):
> handle_request(rq)
>
> Peter

and the next step on from this is to realise that the problem isn't how to
code the calls to get_request(), the problem is actually that get_request()
itself isn'ty Pythonic. Rewrite it as a generator, rename it to reflect
that it now generates a sequence of requests and the code becomes:

for rq in incoming_requests(...):
handle_request(rq)


--
Duncan Booth http://kupuguy.blogspot.com


== 5 of 6 ==
Date: Wed, Feb 24 2010 2:38 am
From: Peter Otten <__peter__@web.de>


Duncan Booth wrote:

> Peter Otten <__peter__@web.de> wrote:
>
>> Ulrich Eckhardt wrote:
>>
>>> I'm looking for a way to write code similar to this C code:
>>>
>>> while(rq = get_request(..)) {
>>> handle_request(rq);
>>> }
>>>
>> Assuming get_request(...) is called with the same arguments on each
>> iteration and uses None to signal that there is no more data:
>>
>> from functools import partial
>>
>> for rq in iter(partial(get_request, ...), None):
>> handle_request(rq)
>>
>> Peter
>
> and the next step on from this is to realise that the problem isn't how to
> code the calls to get_request(), the problem is actually that
> get_request() itself isn'ty Pythonic. Rewrite it as a generator, rename it
> to reflect that it now generates a sequence of requests and the code
> becomes:
>
> for rq in incoming_requests(...):
> handle_request(rq)

...and a likely implementation would be

def incoming_requests(...):
while True:
rq = ... # inlined version of get_request()
if not rq:
break
yield rq

In other words: It's turtles all the way down...

Peter

== 6 of 6 ==
Date: Wed, Feb 24 2010 3:24 am
From: Ulrich Eckhardt


Peter Otten wrote:
> Duncan Booth wrote:
>> for rq in incoming_requests(...):
>> handle_request(rq)
>
> ...and a likely implementation would be
>
> def incoming_requests(...):
> while True:
> rq = ... # inlined version of get_request()
> if not rq:
> break
> yield rq
>
> In other words: It's turtles all the way down...

Almost. While it moves the ugliness, at least it allows separating the
iteration logic from the handling logic, which is already a big step ahead!

That said, there is:

with <expression> as <name>:
...

so why not:

while <expression> as <name>:
...

and also:

if <expression> as <name>:
...


Thanks to everybody for their input!

Uli

--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932


==============================================================================
TOPIC: Signature-based Function Overloading in Python
http://groups.google.com/group/comp.lang.python/t/7abc18970a1757e7?hl=en
==============================================================================

== 1 of 2 ==
Date: Wed, Feb 24 2010 2:28 am
From: Jean-Michel Pichavant


Michael Rudolf wrote:
> Just a quick question about what would be the most pythonic approach
> in this.
>
> In Java, Method Overloading is my best friend, but this won't work in
> Python:
>
> >>> def a():
> pass
> >>> def a(x):
> pass
> >>> a()
> Traceback (most recent call last):
> File "<pyshell#12>", line 1, in <module>
> a()
> TypeError: a() takes exactly 1 argument (0 given)
>
> So - What would be the most pythonic way to emulate this?
> Is there any better Idom than:
>
> >>> def a(x=None):
> if x is None:
> pass
> else:
> pass
>
> ?
>
> Thanks,
> Michael
This is the way to do it python, and it has its advantages: 1 docstring,
1 way do do it, 1 interface.

JM


== 2 of 2 ==
Date: Wed, Feb 24 2010 3:42 am
From: Michael Rudolf


First: Thanks for all the replies so far, they really helped me.

Am 24.02.2010 11:28, schrieb Jean-Michel Pichavant:
>> >>> def a(x=None):
>> if x is None:
>> pass
>> else:
>> pass
>>
> This is the way to do it python, and it has its advantages: 1 docstring,
> 1 way do do it, 1 interface.

Yes, I see. Actually I do now realize that even in Java I use method
overloading mostly to implement optional arguments anyway, like:

void constructor(){this.foo='foo'; this.initotherstuff();}
void constructor(int x) {this.x=x; this.constructor();}

and so on.

So most of the time the idiom above is exactly what I need, as the
versions of the function share code anyway.

But there are also cases where they do something completely different -
in these cases I might use one of the other solutions provided here or
simply make two or three functions and name them appropiately.

I do now see that the pythonic approach is the "best" for most cases,
but I really loved to see that you *can* do overloading in a convenient
way if you really want to :D Those decorators just rock :D

Thanks again,
Michael

==============================================================================
TOPIC: Why tarfile.TarFile.gzopen is not in the online documentation?
http://groups.google.com/group/comp.lang.python/t/fc36204286592cee?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Feb 24 2010 2:14 am
From: Lars Gustäbel


On Wed, Feb 24, 2010 at 09:37:19AM +0100, Baptiste Lepilleur wrote:
> I stumbled uppon this and find it somewhat odd: some class methods of
> TarFile and TarInfo do not appears in either the online documentation or
> search while they have a doc string:
>
> http://docs.python.org/search.html?q=gzopen
> http://docs.python.org/library/tarfile.html?highlight=tarfile#tarfile.TarFile
>
> See script at the end for list of class methods.
>
> Is this "by design" or is there some an odd bug in doc generation lurking
> around? This somehow seem to be specific to module tarfile. Fraction
> classmethod from_float() is available in the documentation and found by a
> search for example...

First of all, Python's module documentation is not generated from module
docstrings, each module has its own rst text file in the documentation tree
instead.

But to answer your question: Yes, this is intentional. The TarFile class has
three classmethods taropen(), gzopen(), and bz2open() each for a specific
compression method. These three are used internally by the TarFile.open()
classmethod and are not intended to be called directly. The TarFile.open()
method is the one that is publicly documented and supposed to be used. It
decides which of the three methods to use based on the mode argument and
does many more other high-level things as well.

Regards,

--
Lars Gust�bel
lars@gustaebel.de

I do not care to belong to a club that
accepts people like me as members.
(Groucho Marx)

==============================================================================
TOPIC: Creating variables from dicts
http://groups.google.com/group/comp.lang.python/t/bb1797ffb6fc3bd7?hl=en
==============================================================================

== 1 of 5 ==
Date: Wed, Feb 24 2010 2:44 am
From: Luis M. González


On Feb 24, 4:08 am, Steven D'Aprano
<ste...@REMOVE.THIS.cybersource.com.au> wrote:
> On Tue, 23 Feb 2010 20:44:10 -0800, Luis M. González wrote:
> > On Feb 24, 1:15 am, Steven D'Aprano
> > <ste...@REMOVE.THIS.cybersource.com.au> wrote:
> >> On Tue, 23 Feb 2010 19:47:22 -0800, Luis M. González wrote:
> >> > On Feb 23, 10:41 pm, Steven D'Aprano
> >> > <ste...@REMOVE.THIS.cybersource.com.au> wrote:
> >> >> On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. González wrote:
> >> >> > By the way, if you want the variables inside myDict to be free
> >> >> > variables, you have to add them to the local namespace. The local
> >> >> > namespace is also a dictionary "locals()". So you can update
> >> >> > locals as follows:
>
> >> >> >     locals().update( myDictionary )
>
> >> >> No you can't. Try it inside a function.
>
> >> >> --
> >> >> Steven
>
> >> > Sure. Inside a function I would use globals() instead. Although I
> >> > don't know if it would be a good practice...
>
> >> Er, how does using globals change the local variables?
>
> >> --
> >> Steven
>
> > Hmmm.... well, you tell me!
>
> I'm not the one that said you can update locals! You said it. I said you
> can't, because you *can't*. The docs warn that you can't change locals,
> and if you try it, you will see that the docs are right.
>
> >>> def test():
>
> ...     x = 1
> ...     locals().update(x = 2)
> ...     print x
> ...
>
> >>> test()
>
> 1
>
> > As I said, I don't know if this is the recomended way...
>
> It's not recommended because it doesn't work.
>
> --
> Steven

I guess I have to check the docs...
Anyway, nobody wanted to update locals() from within a function here.
Doing it outside of a function seems to work.
And updating globals() works in any case, which is what the OP seems
to need. Isn't it?

Luis


== 2 of 5 ==
Date: Wed, Feb 24 2010 2:58 am
From: Luis M. González


On Feb 24, 7:44 am, Luis M. González <luis...@gmail.com> wrote:
> On Feb 24, 4:08 am, Steven D'Aprano
>
>
>
>
>
> <ste...@REMOVE.THIS.cybersource.com.au> wrote:
> > On Tue, 23 Feb 2010 20:44:10 -0800, Luis M. González wrote:
> > > On Feb 24, 1:15 am, Steven D'Aprano
> > > <ste...@REMOVE.THIS.cybersource.com.au> wrote:
> > >> On Tue, 23 Feb 2010 19:47:22 -0800, Luis M. González wrote:
> > >> > On Feb 23, 10:41 pm, Steven D'Aprano
> > >> > <ste...@REMOVE.THIS.cybersource.com.au> wrote:
> > >> >> On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. González wrote:
> > >> >> > By the way, if you want the variables inside myDict to be free
> > >> >> > variables, you have to add them to the local namespace. The local
> > >> >> > namespace is also a dictionary "locals()". So you can update
> > >> >> > locals as follows:
>
> > >> >> >     locals().update( myDictionary )
>
> > >> >> No you can't. Try it inside a function.
>
> > >> >> --
> > >> >> Steven
>
> > >> > Sure. Inside a function I would use globals() instead. Although I
> > >> > don't know if it would be a good practice...
>
> > >> Er, how does using globals change the local variables?
>
> > >> --
> > >> Steven
>
> > > Hmmm.... well, you tell me!
>
> > I'm not the one that said you can update locals! You said it. I said you
> > can't, because you *can't*. The docs warn that you can't change locals,
> > and if you try it, you will see that the docs are right.
>
> > >>> def test():
>
> > ...     x = 1
> > ...     locals().update(x = 2)
> > ...     print x
> > ...
>
> > >>> test()
>
> > 1
>
> > > As I said, I don't know if this is the recomended way...
>
> > It's not recommended because it doesn't work.
>
> > --
> > Steven
>
> I guess I have to check the docs...
> Anyway, nobody wanted to update locals() from within a function here.
> Doing it outside of a function seems to work.
> And updating globals() works in any case, which is what the OP seems
> to need. Isn't it?
>
> Luis

Alright, this is what the docs say about locals:
"Note
The built-in functions globals() and locals() return the current
global and local dictionary, respectively, which may be useful to pass
around for use as the second and third argument to exec().

Note
The default locals act as described for function locals() below:
modifications to the default locals dictionary should not be
attempted. Pass an explicit locals dictionary if you need to see
effects of the code on locals after function exec() returns."

I wonder why updating locals(), not from within a function, works (at
least in my interactive session).
And what about the trick of updating globals? Is it legal? If not, is
there any "legal" way to do what the OP needs?

Luis


== 3 of 5 ==
Date: Wed, Feb 24 2010 3:38 am
From: Bruno Desthuilliers


Luis M. González a écrit :
> On Feb 23, 5:53 pm, vsoler <vicente.so...@gmail.com> wrote:
>> Hi,
>>
>> I have two dicts
>>
>> n={'a', 'm', 'p'}
>> v={1,3,7}
>>
>> and I'd like to have
>>
>> a=1
>> m=3
>> p=7
>>
>> that is, creating some variables.
>>
>> How can I do this?
>
> You are probably coming from another language and you're not used to
> python's data structures.
> If you want a list of items, you use tuples or lists.

<pedantic>

If you want a list, then you use a list - not a tuple !-)

> Examples:
>
> ('a', 'm', 'p') ---> this is a tuple, and it's made with
> parenthesis ()

It's not the parens that "make" the tuple, it's the commas:

>>> t1 = (1, 2, 3)
>>> t2 = 1, 2, 3
>>> t1
(1, 2, 3)
>>> t2
(1, 2, 3)
>>> type(t2)
<type 'tuple'>
>>>

The only case where the parens are required is to define an empty tuple:
>>> empty = ()
>>> empty
()
>>> type(empty)
<type 'tuple'>

</<pedantic>

Now it's most of the time a good idea to still use the parens since it
makes for more readable code (IMHO...)

(snip helpful content)


== 4 of 5 ==
Date: Wed, Feb 24 2010 3:40 am
From: Bruno Desthuilliers


Luis M. González a écrit :
> On Feb 23, 10:41 pm, Steven D'Aprano
> <ste...@REMOVE.THIS.cybersource.com.au> wrote:
>> On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. González wrote:
>>> By the way, if you want the variables inside myDict to be free
>>> variables, you have to add them to the local namespace. The local
>>> namespace is also a dictionary "locals()". So you can update locals as
>>> follows:
>>> locals().update( myDictionary )
>> No you can't. Try it inside a function.
>>
>
> Sure. Inside a function I would use globals() instead.
> Although I don't know if it would be a good practice...

It's even worse than a bad practice. Hint : why is "globals" named
"globals" and not "locals" ?

== 5 of 5 ==
Date: Wed, Feb 24 2010 3:48 am
From: Bruno Desthuilliers


Luis M. Gonz�lez a �crit :
(snip)
> Alright, this is what the docs say about locals:
> "Note
> The built-in functions globals() and locals() return the current
> global and local dictionary, respectively, which may be useful to pass
> around for use as the second and third argument to exec().
>
> Note
> The default locals act as described for function locals() below:
> modifications to the default locals dictionary should not be
> attempted. Pass an explicit locals dictionary if you need to see
> effects of the code on locals after function exec() returns."
>
> I wonder why updating locals(), not from within a function, works (at
> least in my interactive session).

Because at the top level, locals and globals are the same thing.

> And what about the trick of updating globals? Is it legal?

It's legal, but it's (usually) a very bad idea - at the top-level, it
harms readability, and from within a function it's doubly bad
(readibility + "globals are evil").

Now as usual with GoldenRules(tm), it's meant to be broken - once you do
know why you shouldn't _usually_ do it.


for the very same reasons global

> If not, is
> there any "legal" way to do what the OP needs?
>
> Luis

==============================================================================
TOPIC: "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies free
download" on http://sexyandpretty-girls.blogspot.com/
http://groups.google.com/group/comp.lang.python/t/1f799075f05d91a2?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Feb 24 2010 3:06 am
From: Naeem


"selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies
free download" on http://sexyandpretty-girls.blogspot.com/
"selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies
free download" on http://sexyandpretty-girls.blogspot.com/
"selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies
free download" on http://sexyandpretty-girls.blogspot.com/
"selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies
free download" on http://sexyandpretty-girls.blogspot.com/
"selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies
free download" on http://sexyandpretty-girls.blogspot.com/
"selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies
free download" on http://sexyandpretty-girls.blogspot.com/
"selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies
free download" on http://sexyandpretty-girls.blogspot.com/
"selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies
free download" on http://sexyandpretty-girls.blogspot.com/
"selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies
free download" on http://sexyandpretty-girls.blogspot.com/
"selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies
free download" on http://sexyandpretty-girls.blogspot.com/
"selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies
free download" on http://sexyandpretty-girls.blogspot.com/
"selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies
free download" on http://sexyandpretty-girls.blogspot.com/
"selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies
free download" on http://sexyandpretty-girls.blogspot.com/
"selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies
free download" on http://sexyandpretty-girls.blogspot.com/
"selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies
free download" on http://sexyandpretty-girls.blogspot.com/
"selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies
free download" on http://sexyandpretty-girls.blogspot.com/
"selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies
free download" on http://sexyandpretty-girls.blogspot.com/
"selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies
free download" on http://sexyandpretty-girls.blogspot.com/
"selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies
free download" on http://sexyandpretty-girls.blogspot.com/
"selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies
free download" on http://sexyandpretty-girls.blogspot.com/
"selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies
free download" on http://sexyandpretty-girls.blogspot.com/
"selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies
free download" on http://sexyandpretty-girls.blogspot.com/
"selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies
free download" on http://sexyandpretty-girls.blogspot.com/
"selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers"
"hollywood sexiest scenes" "hollywood blue films" "hollywood movies
free download" on http://sexyandpretty-girls.blogspot.com/
vv

==============================================================================
TOPIC: scope of generators, class variables, resulting in global na
http://groups.google.com/group/comp.lang.python/t/b1ff4d23cb5ec32c?hl=en
==============================================================================

== 1 of 2 ==
Date: Wed, Feb 24 2010 3:52 am
From: Nomen Nescio


Hello,

Can someone help me understand what is wrong with this example?

class T:
A = range(2)
B = range(4)
s = sum(i*j for i in A for j in B)

It produces the exception:

<type 'exceptions.NameError'>: global name 'j' is not defined

The exception above is especially confusing since the following similar example (I just replaced the generator by an explicit array) works:

class T:
A = range(2)
B = range(4)
s = sum([(i*j) for i in A for j in B])

(BTW, the class scope declarations are intentional).

Thanks, Leo.

== 2 of 2 ==
Date: Wed, Feb 24 2010 4:21 am
From: "Alf P. Steinbach"


* Nomen Nescio:
> Hello,
>
> Can someone help me understand what is wrong with this example?
>
> class T:
> A = range(2)
> B = range(4)
> s = sum(i*j for i in A for j in B)
>
> It produces the exception:
>
> <type 'exceptions.NameError'>: global name 'j' is not defined

Which Python implementation are you using?

I can't reproduce the error message that you cite.


<example>
C:\test> py2
Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class T:
... A = range(2)
... B = range(4)
... s = sum(i*j for i in A for j in B)
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in T
File "<stdin>", line 4, in <genexpr>
NameError: global name 'B' is not defined
>>> exit()

C:\test> py3
Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class T:
... A = range(2)
... B = range(4)
... s = sum(i*j for i in A for j in B)
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in T
File "<stdin>", line 4, in <genexpr>
NameError: global name 'B' is not defined
>>> exit()

C:\test> _
</example>

Reason for the NameError:

The above is a /generator expression/, evaluated in a class definition.

The docs have a similar example but I'm sorry, I'm unable to find it! Anyway the
generator expression is evaluated as if its code was put in function. And from
within the scope of that function you can't access the class scope implicitly,
hence, no access to 'B'.

> The exception above is especially confusing since the following similar example
> (I just replaced the generator by an explicit array) works:
>
> class T:
> A = range(2)
> B = range(4)
> s = sum([(i*j) for i in A for j in B])
>
> (BTW, the class scope declarations are intentional).
>
> Thanks, Leo.

This is a /list comprehension/, not a generator expression (although
syntactically it's almost the same).

It obeys different rules.

Essentially the generator expression produces a generator object that you may
name or pass around as you wish, while the comprehension is just a syntactical
device for writing more concisely some equivalent code that's generated inline.

However, apparently the rules changed between Python 2.x and Python 3.x.

In Python 3.x also the list comprehension fails in a class definition:


<example>
C:\test> py2
Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class T:
... A = range(2)
... B = range(4)
... s = sum([(i*j) for i in A for j in B])
...
>>> exit()

C:\test> py3
Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class T:
... A = range(2)
... B = range(4)
... s = sum([(i*j) for i in A for j in B])
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in T
File "<stdin>", line 4, in <listcomp>
NameError: global name 'B' is not defined
>>> exit()

C:\test> _
</example>


From one point of view it's good that Py3 provides about the same behavior for
generator expressions and list comprehensions.

But I'd really like the above examples to Just Work. :-)


Cheers & hth.,

- Alf

==============================================================================
TOPIC: WANTED: Regular expressions for breaking TeX/LaTeX document into tokens
http://groups.google.com/group/comp.lang.python/t/ef9f01798e857e5e?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Feb 24 2010 4:03 am
From: Jonathan Fine


Hi

Does anyone know of a collection of regular expressions that will break
a TeX/LaTeX document into tokens? Assume that there is no verbatim or
other category code changes.

Thanks


Jonathan

==============================================================================
TOPIC: Fascism is coming to Internet
http://groups.google.com/group/comp.lang.python/t/6635d24df3ece879?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Feb 24 2010 4:18 am
From: Joan Miller


On 23 feb, 20:16, "D'Arcy J.M. Cain" <da...@druid.net> wrote:
> On Tue, 23 Feb 2010 20:30:03 +0100
>
> Olof Bjarnason <olof.bjarna...@gmail.com> wrote:
> > Even if this is "Off Topic" (which I think it really isn't in any open
> > source / free software-oriented mailing list), I want to agree with
> > Joan.
>
> It isn't about the Python programming language so it is off topic.  So
> what if some members have an interest?  We have interest in a lot of
> things.  We all have interest in the hardware that our programs run on
> but questions about hardware are also off topic.
>
> Perhaps you don't quite grasp the point of topical discussion groups.
> They are a way of letting individuals decide for themselves what kind
> of discussions they want to be involved in.  By spamming the group this
> way you take away that freedom of choice.  It's ironic when it is done
> in the name of freedom.
>
> --

To avoid the spam, I reccomend a mailing list site as librelist:

http://librelist.com/index.html

problem -> reaction -> solution


==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.python"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.python?hl=en

To unsubscribe from this group, send email to comp.lang.python+unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.python/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate