Patrick Maupin | 29 Aug 02:22

Re: exactly same as [1,2,3,] ?

On Aug 28, 6:35 pm, "James Mills" <prolo...@shortcircuit.net.au>
wrote:
> I must point out though that although they contain
> the same elements/data, they are not the same
> object/instance.
>
> {{{
> #!python
>
> >>> x = [1, 2, 3]
> >>> y = [1, 2, 3]
> >>> id(x)
> 3083095148L
> >>> id(y)
> 3082953324L
> >>> x == y
> True
> }}}

Umm, yeah, but that's true of ANY two mutable objects you create, and
has absolutely nothing to do with whether the syntax which generated
the list contains a trailing comma or not.  To wit:

>>> [1,2,3] is [1,2,3]
False

Regards,
Pat
--
http://mail.python.org/mailman/listinfo/python-list
(Continue reading)

Matimus | 29 Aug 01:56

Re: eval() == evil? --- How to use it safely?

On Aug 28, 3:09 pm, "Guilherme Polo" <ggp...@gmail.com> wrote:
> On Thu, Aug 28, 2008 at 6:51 PM, Fett <FettMan...@gmail.com> wrote:
> > I am creating a program that requires some data that must be kept up
> > to date. What I plan is to put this data up on a web-site then have
> > the program periodically pull the data off the web-site.
>
> > My problem is that when I pull the data (currently stored as a
> > dictionary on the site) off the site, it is a string, I can use eval()
> > to make that string into a dictionary, and everything is great.
> > However, this means that I am using eval() on some string on a web-
> > site, which seems pretty un-safe.
>
> > I read that by using eval(code,{"__builtins__":None},{}) I can prevent
> > them from using pretty much anything, and my nested dictionary of
> > strings is still allowable. What I want to know is:
>
> > What are the dangers of eval?
> > - I originally was using exec() but switched to eval() because I
> > didn't want some hacker to be able to delete/steal files off my
> > clients computers. I assume this is not an issue with eval(), since
> > eval wont execute commands.
> > - What exactly can someone do by modifying my code string in a command
> > like: thing = eval(code{"__builtins__":None},{}), anything other than
> > assign their own values to the object thing?
>
> By "disabling" __builtins__ you indeed cut some obvious tricks, but
> someone still could send you a string like "10 ** 10 ** 10".
>
> > --
> >http://mail.python.org/mailman/listinfo/python-list
(Continue reading)

saswat@gmail.com | 29 Aug 01:41

Re: Checking if the file is a symlink fails

On Aug 28, 3:11 pm, Christian Heimes <li...@cheimes.de> wrote:
> sas...@gmail.com wrote:
> > File symLinkTest is a symbolic link.
>
> > Why S_ISLNK(mode) returns False and S_ISREG(mode) returns True ?
>
> Because you are using os.stat() instead of os.lstat().
>
> http://docs.python.org/lib/os-file-dir.html
>
> Christian

Do you mean the following is deprecated ?
http://docs.python.org/lib/module-stat.html

>From the documentation -

S_ISLNK( mode)
    Return non-zero if the mode is from a symbolic link.

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

mh | 29 Aug 01:31

Re: [1,2,3] exactly same as [1,2,3,] ?

Paul McNett <p <at> ulmcnett.com> wrote:
> When confronted with this type of question, I ask the interpreter:
>  >>> [1,2,3] == [1,2,3,]
> True

Well I guess that's a pretty authoritative answer... thanks!

--

-- 
Mark Harrison
Pixar Animation Studios
--
http://mail.python.org/mailman/listinfo/python-list

mh | 29 Aug 01:17

[1,2,3] exactly same as [1,2,3,] ?

x=[1,2,3]
and
x=[1,2,3,]

are exactly the same, right?

I'm generating some python data, and it's less error prone
to not treat the last element specially, but I want to be
sure I'm generating an equivalent data structure.

Many TIA!
Mark

--

-- 
Mark Harrison
Pixar Animation Studios
--
http://mail.python.org/mailman/listinfo/python-list

W. eWatson | 29 Aug 00:04

Python in a Nutshell -- Book vs Web

I read an Amazon of Python in a Nutshell. The first edition is supposedly 
much like the web site. What web site? The second edition apparently adds 
more to the book than the web site.
--

-- 
            Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

              (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
               Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

                     Web Page: <www.speckledwithstars.net/>
--
http://mail.python.org/mailman/listinfo/python-list

saswat@gmail.com | 28 Aug 23:52

Checking if the file is a symlink fails


check if file is a symlink
Here is a small piece of code:

import os
from stat import *

filePath = "/home/xyz/symLinkTest"
mode = os.stat(filePath)[ST_MODE]

print 'Find using os.path : ',os.path.islink(filePath)

print 'Find using mode :', S_ISLNK(mode)
print 'Is this a regular file : ' S_ISREG(mode)

Output :
---------

Find using os.path : True
Find using mode : False
Is this a regular file :  True

File symLinkTest is a symbolic link.

Why S_ISLNK(mode) returns False and S_ISREG(mode) returns True ?

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

(Continue reading)

Fett | 28 Aug 23:47

eval() == evil? --- How to use it safely?

I am creating a program that requires some data that must be kept up
to date. What I plan is to put this data up on a web-site then have
the program periodically pull the data off the web-site.

My problem is that when I pull the data (currently stored as a
dictionary on the site) off the site, it is a string, I can use eval()
to make that string into a dictionary, and everything is great.
However, this means that I am using eval() on some string on a web-
site, which seems pretty un-safe.

I read that by using eval(code,{"__builtins__":None},{}) I can prevent
them from using pretty much anything, and my nested dictionary of
strings is still allowable. What I want to know is:

What are the dangers of eval?
- I originally was using exec() but switched to eval() because I
didn't want some hacker to be able to delete/steal files off my
clients computers. I assume this is not an issue with eval(), since
eval wont execute commands.
- What exactly can someone do by modifying my code string in a command
like: thing = eval(code{"__builtins__":None},{}), anything other than
assign their own values to the object thing?
--
http://mail.python.org/mailman/listinfo/python-list

castironpi | 28 Aug 23:15

Re: Negative regular expressions (searching for "i" not inside command)

On Aug 28, 4:04 pm, "Guilherme Polo" <ggp...@gmail.com> wrote:
> On Thu, Aug 28, 2008 at 5:04 PM, Bart Kastermans
>
> <kaste...@math.wisc.edu${hostname}> wrote:
> > I have a file in which I am searching for the letter "i" (actually
> > a bit more general than that, arbitrary regular expressions could
> > occur) as long as it does not occur inside an expression that matches
> > \\.+?\b (something started by a backslash and including the word that
> > follows).
>
> > More concrete example, I have the string "\sin(i)" and I want to match
> > the argument, but not the i in \sin.
>
> > Can this be achieved by combining the regular expressions?  I do not
> > know the right terminology involved, therefore my searching on the
> > Internet has not led to any results.
>
> Try searching again with the "lookahead" term, or "negative lookahead".
>
>
>
> > I can achieve something like this by searching for all i and then
> > throwing away those i that are inside such expressions.  I am now just
> > wondering if these two steps can be combined into one.
>
> > Best,
> > Bart
> > --
> >http://www.bartk.nl/
> > --
(Continue reading)

GHZ | 28 Aug 12:16

filter in for loop

I would like to say something like:

for x in l if <expression>:
    <do something>

e.g.

for filename in os.listdir(DIR) if filename[-4:] == '.xml':
    <do something>

instead of having to say:

for filename in os.listdir(DIR):
    if filename[-4:] == '.xml':
        <do something>

or

for filename in (f for f in os.listdir(DIR) if f[-4] == '.xml'):
    <do something>

is there a shortcut I'm missing?
--
http://mail.python.org/mailman/listinfo/python-list

Juan | 28 Aug 11:55

PYTHONPATH and modules

Hi

I am programming a little script that makes use of a module I
developed before. The utils are inside the directory src of the
directory utils, and the package is nutum.utils. The script is in the
directory src inside the directory sysinfo, and the package is
nutum.sysinfo. Well, if not clear, this is the list of files:

ls -lR ~/workspace (imaginary output):

utils/src/nutum/__init__.py
utils/src/nutum/utils/__init__.py
utils/src/nutum/utils/general.py
utils/src/nutum/utils/elapsed_time.py
utils/src/nutum/utils/execute_command.py
utils/src/nutum/utils/size_units.py

sysinfo/src/nutum/__init__.py
sysinfo/src/nutum/sysinfo/__init__.py
sysinfo/src/nutum/sysinfo/sysinfo.py
sysinfo/src/nutum/sysinfo/modules/__init__.py
sysinfo/src/nutum/sysinfo/modules/base_module.py
sysinfo/src/nutum/sysinfo/modules/os.py

So, when from the home directory I run this command:

PYTHONPATH=workspace/utils/src/:workspace/sysinfo/src python -m
nutum.sysinfo.sysinfo --config-file /home/juan/sysinfo.config.ini

I get this output:
(Continue reading)


Gmane