Re: Looking for Remote Python Project

2011-01-30 Thread Ben Finney
joy99  writes:

> But do you know whether it would be a paying one, I am looking to be a
> freelancer.

You might find the Python Job Board useful
http://www.python.org/community/jobs/>.

-- 
 \“Choose mnemonic identifiers. If you can't remember what |
  `\mnemonic means, you've got a problem.” —Larry Wall |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Use the Source Luke

2011-01-30 Thread Steven D'Aprano
On Sat, 29 Jan 2011 20:50:20 -0800, rusi wrote:

> On Jan 30, 9:21 am, Steven D'Aprano  +comp.lang.pyt...@pearwood.info> wrote:
>>
>> > I think this is a fairly accurate description of (one aspect of) the
>> > problem.
>> > If you dont see it as a problem how do you explain that google can
>> > search the World Wide Web better than we can search our individual
>> > hard disks?
>>
>> I fail to see any connection between the location that operating
>> systems store files, and the ability of Google to index publicly
>> available websites.
> 
> http://en.wikipedia.org/wiki/Content-addressable_storage#Content-
addressed_vs._Location-addressed


Nope, sorry, doesn't help. Both local files on your hard drive, and most 
remote websites on the Internet, are location addressed. Google indexes 
the content, but they don't provide content-addresses. Indeed, they 
*can't* do so (except, possibly, for content they control such as Google 
Books), since they can't prevent content owners from modifying either the 
location address or the content. And as I've mentioned, there are desktop 
utilities that index content for Windows and Macintosh. In fact, Google 
themselves offer a desktop app that does just that:

http://desktop.google.com/features.html



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


Re: multiple values for keyword argument

2011-01-30 Thread Steven D'Aprano
On Sat, 29 Jan 2011 10:39:49 -0800, patty wrote:

> I am glad you said this.  I have been avoiding understanding this
> 'self', just accepting it :}  For the time being, since my programs I am
> creating are for my own use, I think I will make my own names up, that
> are descriptive to me as the programmer, it's all going to be
> interpreted anyway.  And the other email equating to C's argv, etc. -
> now I get it.


That's a shame, because `self` is actually very simple once you 
understand the basic principles of object-oriented programming.

What names would you choose? Unless you're writing descriptors, or using 
class methods, both of which should be considered advanced usage (highly 
advanced for descriptors, moderately so for class methods), it's not like 
every method needs a different descriptive first argument. In English, 
"self", "this", "me" or "instance" would be good names. What else would 
you use?


The idea of method syntax is that you start with an instance of some 
class:

mystring = "hello world"  # an instance of the str class

In procedural languages like C or Pascal, you would call a function and 
give the string as an argument. Python supports this programming model, 
and uses it for built-ins like len:

len(mystring)
=> returns 11


Object oriented programming uses a different syntax. Instead of 

function(instance)

as above, we take the instance argument outside the brackets. For example:

mystring.upper()  # instead of upper(mystring)
=> returns "HELLO WORLD"

If there are any extra arguments needed, they go inside the brackets as 
normal.

So far, this is just a change of syntax. It's like saying "The cat of my 
brother's" vs. "my brother's cat" -- the meaning is the same, but the 
syntax differs. The real advantages of object oriented programming and 
methods come elsewhere (e.g. encapsulation and inheritance).

[Aside: when I was learning this, the hardest part I found was
remembering which things were functions, and which were methods. 
I kept writing (wrongly!) things like:

"hello world".len()
upper("hello world")

Unfortunately there is no easy way to recognise what will be a
function like len, and which are methods like upper. That will 
come with experience.

Back to function/procedural syntax versus object oriented syntax... 

One difference, though, is when you write a method definition. Because 
the method you write starts off life as an ordinary function, you need to 
write it *as if* it were a function you call like len() above. Here's how 
you might write a method in a class:

class MyClass:
def method(self, extra):
pass

When you then call the method:

instance = MyClass()
instance.method("something extra")

Python automatically changes the syntax for you, and passes two arguments 
to the function as if you did this:

# pseudo-code
set self = instance
set extra = "something extra
extract "method" from MyClass
call method(self, extra)

We call the first argument something like "self" because it will ALWAYS 
be the instance itself. Unlike a regular function, which can have 
anything passed as the first argument, and therefore you should give it a 
descriptive name, the method's first argument is provided automatically 
for you and will always be the instance you started with.



I hope this helps.




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


Re: Use the Source Luke

2011-01-30 Thread David Boddie
On Sunday 30 January 2011 05:21, Steven D'Aprano wrote:

> If I *wanted* to index my files, I could do so, although in
> fairness I'm not aware of any Linux tools which do this -- I know of
> `locate`, which indexes file *names* but not content, and `grep`, which
> searches file content but doesn't index what it finds.

You might find this page useful:

http://www.wikinfo.org/index.php/Comparison_of_desktop_search_software

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


Re: Is it possible to pass CSV Reader Object As Argument to another Python File ???

2011-01-30 Thread bansi
On Jan 28, 4:22 pm, Benjamin Kaplan  wrote:
> On Fri, Jan 28, 2011 at 3:42 PM, bansi  wrote:
> > On Jan 28, 1:52 pm, Benjamin Kaplan  wrote:
> >> On Fri, Jan 28, 2011 at 1:33 PM, bansi  wrote:
> >> > On Jan 28, 9:46 am, bansi  wrote:
> >> >> On Jan 26, 8:31 pm, MRAB  wrote:
>
> >> >> > On 27/01/2011 00:57, bansi wrote:
>
> >> >> > > On Jan 26, 6:25 pm, Ethan Furman  wrote:
> >> >> > >> bansi wrote:
>
> >> >> > >>   >  First namelookupWrapper.py running under Python 2.6 accept 
> >> >> > >> arguments
> >> >> > >>   >  from stdin and uses csv reader object to read it i.e.
> >> >> > >>   >  r=csv.reader(sys.stdin)
>
> >> >> > >>   >  And then it has to pass csv reader object to another python 
> >> >> > >> script
> >> >> > >>   >  namelookup.py running under Python 2.7 because it uses pyodbc 
> >> >> > >> to
> >> >> > >>   >  connect to database and iterates thru reader object
>
> >> >> > >> Ben Finney wrote:
> >> >> > >>> bansi  writes:
>
> >> >> >  Thanks Chris. Sorry for mis-communicating, the two python 
> >> >> >  scripts are
> >> >> >  dependant in a way that namelookupWrapper.py needs to pass csv 
> >> >> >  record
> >> >> >  object to another python script
>
> >> >> > >>> Why have you structured them that way, though? What constraint is
> >> >> > >>> keeping you from doing the work in a single process, where the CSV
> >> >> > >>> reader object can be shared?
>
> >> >> >  If thats not possible then please let me know how to do the 
> >> >> >  workaround
> >> >> >  i didnt understood the import thing and not sure if it helps in 
> >> >> >  my
> >> >> >  case
>
> >> >> > >>> The problem as you've described it so far is best solved by 
> >> >> > >>> having a
> >> >> > >>> single process accessing the CSV reader object in memory. If that
> >> >> > >>> doesn't suit your use case, you'll need to explain why not.
>
> >> >> > >> In other words, why can't you use Python 2.7 to accept input and
> >> >> > >> generate a csv.reader?
>
> >> >> > >> ~Ethan~- Hide quoted text -
>
> >> >> > >> - Show quoted text -
>
> >> >> > > Ethan,
> >> >> > > The python script takes the input from Splunk 
> >> >> > > (http://www.splunk.com/
> >> >> > > base/Documentation/) which supports only Python 2.6
> >> >> > > So the real constraint is Splunk supports only Python 2.6 .
>
> >> >> > > As you know Python 2.6 doesnt support or doesnt have pyodbc install
> >> >> > > for Windows  64 bit OS
> >> >> > > So i installed Python 2.7 and thereafter pyodbc install for Windows 
> >> >> > > 64
> >> >> > > bit OS for Python 2.7
>
> >> >> > Have you actually tried Splunk with Python 2.7? It might not work with
> >> >> > versions which are earlier than Python 2.6, but that doesn't
> >> >> > necessarily mean that it won't work with versions of Python 2 which 
> >> >> > are
> >> >> > later than Python 2.6 (unless the documentation says that it must be
> >> >> > Python 2.6).- Hide quoted text -
>
> >> >> > - Show quoted text -
>
> >> >> Splunk's latest version 4.1.6 doesn't support Python 2.7
> >> >> I tried the import trick but it didnt work because the real script
> >> >> which runs under Python 2.7 has import pyodbc so it results in
> >> >> following error
>
> >> >> c:\Splunk\etc\apps\search\bin>splunk cmd python namelookupWrapper.py
> >> >> memberId memberName < memberInput.csv
> >> >> Traceback (most recent call last):
> >> >>   File "namelookupWrapper.py", line 3, in 
> >> >>     import namelookup
> >> >>   File "c:\Splunk\etc\apps\search\bin\namelookup.py", line 7, in
> >> >> 
> >> >>     import pyodbc
> >> >> ImportError: DLL load failed: The specified module could not be found.
>
> >> >> Please let me know if i am missing something on import. If so please
> >> >> provide me with an example- Hide quoted text -
>
> >> >> - Show quoted text -
>
> >> > Here are some more details from my earlier posting. Please click the
> >> > below link
>
> >> >http://answers.splunk.com/questions/11145/its-getting-mysterious-to-m...
> >> > --
> >> >http://mail.python.org/mailman/listinfo/python-list
>
> >> Have you tried downloading the source for PyODBC and compiling it
> >> yourself? All you need to do is python setup.py install. My guess
> >> would be that it works just fine on 64-bit Python 2.6, they just never
> >> released a re-compiled version of it for that platform.- Hide quoted text -
>
> >> - Show quoted text -
>
> > Thanks Benjamin. Please point me to the website from where i can
> > download pyodbc for Windows 64 bit OS under Python 2.6 and
> > installation instructions
> > --
>
> You don't download it for 64-bit Windows with Python 2.6. You download
> the source code from the website and make the Python 2.6, 64-bit
> Windows version yourself.
>
> Download the source zip file and extract it. Then, open up the command
> prompt and use the "cd" command to change directories to that source
> folder. For instance, if the source code has been extracted to
> C:\pyodbc-2.1.8\, you type in "cd C:\pyodbc-2.1.8" and 

Re: Use the Source Luke

2011-01-30 Thread Tim Wintle
On Sat, 2011-01-29 at 21:17 -0800, Raymond Hettinger wrote:
> My thesis is that we can do even better than that by adding
> direct links from the docs to the relevant code with nice
> syntax highlighting.

+1 - I think the source links are very useful (and thanks for pushing
them).


However I think the biggest changes that have probably happened with
python itself are:

 (1) More users for whom this is their first language.
 (2) CS courses / training not teaching C (or pointer-based languages).

(2) is especially important IMO - under half of the python developers I
have regularly worked with would feel comfortable reading C - so for the
other half reading C source code probably isn't going to help them
understand exactly what's going on (although in the long run it might
help them a lot)


Tim Wintle

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


Re: Use the Source Luke

2011-01-30 Thread rantingrick
On Jan 30, 2:53 am, Steven D'Aprano  wrote:

> In fact, Google
> themselves offer a desktop app that does just that:
>
> http://desktop.google.com/features.html

Yes, but at the expense of your privacy! How much private information
is being sent back to Google plex an used to flash more click ads at
you? Well i guess we could say, google does spam us, but at least we
are more likely to be *slightly* interested in the spam.

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


Re: Use the Source Luke

2011-01-30 Thread rusi
On Jan 30, 6:19 pm, David Boddie  wrote:

> You might find this page useful:
>
> http://www.wikinfo.org/index.php/Comparison_of_desktop_search_software
>
> David

Thanks for that link David

I note particularly the disclaimer that it was removed from wikipedia
[Like when  censors stuff you know it
deserves a second look ;-) ]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to pass CSV Reader Object As Argument to another Python File ???

2011-01-30 Thread rusi
On Jan 30, 6:31 pm, bansi  wrote:
> On Jan 28, 4:22 pm, Benjamin Kaplan  wrote:
>
> > You'll need to have Visual C++ 2008 (not 2010) installed for this to
> > work. You can get it for free 
> > fromhttp://www.microsoft.com/express/Downloads/if
> > you don't already have it.
>
>
> Thanks Benjamin. Wondering why i need to Visual C++ 2008 . What it has
> to do with Python?
> Isn't it possible to implement your suggestion without installing
> Visual C++ 2008 .


http://code.google.com/p/pyodbc/wiki/Building#Windows
-- 
http://mail.python.org/mailman/listinfo/python-list


how to modify axis tick values exponential value location in matplotlib

2011-01-30 Thread Rajendra prasad Gottipati
Hi,

I am plotting the graph for long values like(267838484) so that its printing
the tick lables on axes as 2.6 , 2.8 and at the top its having a text like
e07 something like this, I want to move the display location of this
exponent (e07) as i am having trouble in having multiple y-axis as they are
getting mixed in text. like (e07 is written on top of e08 of other axis)

Can any one help me in getting this done? also i am having issue in getting
tick lables of x-axis while plotting with pylab.plot_date.


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


Style question: Nicknames for deeply nested objects

2011-01-30 Thread Gerald Britton
Hi all,

Today I was thinking about a problem I often encounter.  Say that I
have (seems I often do!) a deeply nested object, by which I mean
object within object with object, etc.

For example:

   x = some.deeply.nested.object.method(some.other.deeply.nested.object.value)

Well, that's extreme but I've worked with code approaching that level
of nested-ness.  Now, consider two scenarios:

1. You need to call this thing many times with different arguments, so
you wind up with:

   x = some.deeply.nested.object.method(some.other.deeply.nested.object.value1)
   y = some.deeply.nested.object.method(some.other.deeply.nested.object.value2)
   z = some.deeply.nested.object.method(some.other.deeply.nested.object.value3)

2. You call it inside a loop:

   for item in some_iterable:
       x = 
some.deeply.nested.object.method(some.other.deeply.nested.object.value)

For one thing, I find the long lines unattractive at best and
error-prone at worst, especially if I also have

   some.other.deeply.nested.object.method

that I might confuse with the first.  To make it look better I might do this:

   _o = some.deeply.nested.object
   _o.method(_o.value)

which is fine, I suppose.

Then, putting on my company hat, I remembered that, from VBA, you could do this:

   with some.deeply.nested.object
       .method(.value)
   end with

I like the structure of this, since the subordinate block can be
indented, which makes it stand out.  Also, it avoids temporary
variables.

So, I was thinking of how to get close to this in Python.  I came up
with two approaches:

1.

   _o = some.deeply.nested.object
   if 1:
       _o.method(_o.value)

The "if 1:" forces me to indent the subordinate code, which sets it
apart from the surrounding code.  Note that I cannot just
indent because I feel like it since Python is persnickety about indentation.

2.

for _o in [some.deeply.nested.object]:
       _o.method(_o.value)

The "for..." sets up the iterator and forces me to indent the subordinate code.

As an aside, approach 1 generates less byte-code since approach 2 sets
up loop machinery which you don't really need in this case.

I have a couple of questions:

1. If you had to choose between approaches 1 and 2, which one would
you go for, and why?

2. What other techniques have you used in such a situation?


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


Re: Style question: Nicknames for deeply nested objects

2011-01-30 Thread rantingrick
On Jan 30, 11:51 am, Gerald Britton  wrote:

[...]

> that I might confuse with the first.  To make it look better I might do this:
>
>    _o = some.deeply.nested.object
>    _o.method(_o.value)
>
> which is fine, I suppose.

It is very fine. And you "supposed" correctly!


> Then, putting on my company hat, I remembered that, from VBA, you could do 
> this:
>
>    with some.deeply.nested.object
>        .method(.value)
>    end with
>
> I like the structure of this, since the subordinate block can be
> indented, which makes it stand out.  Also, it avoids temporary
> variables.

Yes it is a good idea! Well forgetting the horrendous VBA syntax this
is. I brought this up many moons back as a feature request: Local
Blocks. Here is how a pythonic local block would look

with this as localvar:
localvar.do_something()


> So, I was thinking of how to get close to this in Python.  I came up
> with two approaches:
>
> 1.
>
>    _o = some.deeply.nested.object
>    if 1:
>        _o.method(_o.value)

bad idea!


> 2.
>
>     for _o in [some.deeply.nested.object]:
>        _o.method(_o.value)

even worse idea!


> I have a couple of questions:
>
> 1. If you had to choose between approaches 1 and 2, which one would
> you go for, and why?

neither! Stick with the original.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to modify axis tick values exponential value location in matplotlib

2011-01-30 Thread Rajendra prasad Gottipati
it seems relevant to my issue.

http://stackoverflow.com/questions/3677368/matplotlib-format-axis-offset-values-to-whole-numbers-or-specific-number

On Sun, Jan 30, 2011 at 9:45 AM, Rajendra prasad Gottipati <
rajendra4li...@gmail.com> wrote:

> Hi,
>
> I am plotting the graph for long values like(267838484) so that its
> printing the tick lables on axes as 2.6 , 2.8 and at the top its having a
> text like e07 something like this, I want to move the display location of
> this exponent (e07) as i am having trouble in having multiple y-axis as they
> are getting mixed in text. like (e07 is written on top of e08 of other axis)
>
> Can any one help me in getting this done? also i am having issue in getting
> tick lables of x-axis while plotting with pylab.plot_date.
>
>
> Regards
> Raja
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Style question: Nicknames for deeply nested objects

2011-01-30 Thread Roy Smith
In article ,
 Gerald Britton  wrote:

> 1. You need to call this thing many times with different arguments, so
> you wind up with:
> 
>    x = 
> some.deeply.nested.object.method(some.other.deeply.nested.object.value1)
>    y = 
> some.deeply.nested.object.method(some.other.deeply.nested.object.value2)
>    z = 
> some.deeply.nested.object.method(some.other.deeply.nested.object.value3)

I would probably turn that into:

object = some.deeply.nested.object
object.method(object.value1)
object.method(object.value2)
object.method(object.value3)

i.e. make the temporary variable have the exact same name as the last 
component of the deeply nested thing you're trying to refactor.  If the 
scope of use is small and the meaning is obvious from context, sometimes 
I'll shorten the name, i.e.

 obj = some.deeply.nested.object

or even

 o = some.deeply.nested.object

but I tend to avoid doing that.  I'd rather be a little more verbose in 
preference to being a little more cryptic.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Style question: Nicknames for deeply nested objects

2011-01-30 Thread Stephen Hansen
On 1/30/11 9:51 AM, Gerald Britton wrote:
> 1. If you had to choose between approaches 1 and 2, which one would
> you go for, and why?

Neither. Ideally, I'd tweak the API around so the deeply nested
structure isn't something I need to access regularly. But! If you can't
do that, I'd do something like:

--- start
from contextlib import contextmanager

class Item(object): pass

deeply = Item()
deeply.nested = Item()
deeply.nested.thing = Item()

@contextmanager
def my(thing):
yield thing


with my(deeply.nested.thing) as o:
o.hello = 1

print deeply.nested.thing.hello
--- end

That's a dummy context-manager which basically does nothing: it just
"abuses" the context manager protocol to basically make a local variable
and indent its usage. Its really just a run-around and slightly less
efficient to do:

>_o = some.deeply.nested.object
>_o.method(_o.value)

But with the whitespace added on.

Personally, I'd usually just make a local variable and skip any tricks.

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/



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


Re: Style question: Nicknames for deeply nested objects

2011-01-30 Thread rantingrick
On Jan 30, 12:23 pm, Stephen Hansen  wrote:

> --- start
> from contextlib import contextmanager
>
> class Item(object): pass
>
> deeply = Item()
> deeply.nested = Item()
> deeply.nested.thing = Item()
>
> @contextmanager
> def my(thing):
>     yield thing
>
> with my(deeply.nested.thing) as o:
>     o.hello = 1
>
> print deeply.nested.thing.hello
> --- end

Well congratulations Stephen, you win the obfuscation prize of the
year!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Style question: Nicknames for deeply nested objects

2011-01-30 Thread Stephen Hansen
On 1/30/11 10:35 AM, rantingrick wrote:
> Well congratulations Stephen, you win the obfuscation prize of the
> year!

Yes,

On 1/30/11 10:09 AM, rantingrick wrote:
> Here is how a pythonic local block would look
>
> with this as localvar:
> localvar.do_something()

verses

with my(this) as localvar:
localvar.do_something()

Is dreadfully more, er, obfuscated.

I mean someone would have to know what the 'my' function does to
understand what's going on!

OH MY GOD. How can someone be expected to understand what a function does!

Be serious! You can't expect that of them.

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/



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


Understanding def foo(*args)

2011-01-30 Thread sl33k_
Hi,

I am struggling to grasp this concept about def foo(*args). Also, what
is def bar(*args, *kwargs)?

Isnt it like self must be the first parameter to the method/function?
If not what are the exceptions?

Also, can the terms method and function be used interchangeably?

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


Re: Understanding def foo(*args)

2011-01-30 Thread sl33k_
Sorry that parameter is **kwargs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Understanding def foo(*args)

2011-01-30 Thread rantingrick
On Jan 30, 1:26 pm, sl33k_  wrote:
> Hi,
>
> I am struggling to grasp this concept about def foo(*args). Also, what
> is def bar(*args, *kwargs)?

FYI: the python intepretor is your friend!

py> def foo(*args):
print args

py> foo(1)
(1,)

py> foo(1,2,3)
(1, 2, 3)

py> foo(1,[1,23], {'hat':'cat'})
(1, [1, 23], {'hat': 'cat'})

py> def bar(*args, **kw):
print 'Args:', args
print 'Kwds:', kw

py> bar(1,2,3, hat='cat', spam='eggs')
Args: (1, 2, 3)
Kwds: {'hat': 'cat', 'spam': 'eggs'}


> Isnt it like self must be the first parameter to the method/function?
> If not what are the exceptions?

Only *must* with methods!

> Also, can the terms method and function be used interchangeably?

Can the terms cars and truck be used interchangeably?

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


Re: Understanding def foo(*args)

2011-01-30 Thread Mel
sl33k_ wrote:

> Hi,
> 
> I am struggling to grasp this concept about def foo(*args). Also, what
> is def bar(*args, *kwargs)?
> 
> Isnt it like self must be the first parameter to the method/function?
> If not what are the exceptions?
> 
> Also, can the terms method and function be used interchangeably?
> 
> TIA

Try

def foo (*args):
print 'foo args:', repr (args)

foo (1, 2, 3, 4)

def bar (*args, **kwargs):
print 'bar args:', args
print 'bar kwargs:', kwargs

bar (1, 2, 3, 4)
bar (1, 2, 3, baz=6, boz=None)


Mel.

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


Re: Understanding def foo(*args)

2011-01-30 Thread Chris Rebert
On Sun, Jan 30, 2011 at 11:26 AM, sl33k_  wrote:
> Hi,
>
> I am struggling to grasp this concept about def foo(*args).

The interactive interpreter is your friend! Try experimenting with it next time!

http://docs.python.org/tutorial/controlflow.html#arbitrary-argument-lists
That `def` defines a variadic function; i.e. a function which takes an
arbitrary number of positional arguments.
`args` will be a tuple of all the positional arguments passed to the function:
>>> def foo(*args):
... print args
...
>>> foo(1)
(1,)
>>> foo(1,2)
(1, 2)
>>> foo(1,2,3)
(1, 2, 3)

If positional parameters precede the *-parameter, then they are
required and the *-parameter will receive any additional arguments:
>>> def qux(a, b, *args):
... print 'a is', a
... print 'b is', b
... print 'args is', args
...
>>> qux(1)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: qux() takes at least 2 arguments (1 given)
>>> qux(1, 2)
a is 1
b is 2
args is ()
>>> qux(1, 2, 3)
a is 1
b is 2
args is (3,)
>>> qux(1, 2, 3, 4)
a is 1
b is 2
args is (3, 4)

> Also, what is def bar(*args, *kwargs)?

You meant: def bar(*args, **kwargs)

See http://docs.python.org/tutorial/controlflow.html#keyword-arguments
Basically, the **-parameter is like the *-parameter, except for
keyword arguments instead of positional arguments.

> Also, can the terms method and function be used interchangeably?

No. A method is function that is associated with an object (normally
via a class) and takes this object as its first argument (typically
named "self"). A function does not have any of these requirements.
Thus, all method are functions, but the reverse is not true.
(I'm ignoring complexities like classmethods and staticmethods for simplicity.)

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


Re: Understanding def foo(*args)

2011-01-30 Thread Ulrich Eckhardt
sl33k_ wrote:
> Isnt it like self must be the first parameter to the method/function?

"self" is just customary as first parameter to memberfunctions, the 
language itself doesn't impose this convention, as e.g. C++ does with its 
"this".


> Also, can the terms method and function be used interchangeably?

This distinction doesn't exist in Python. You can put a reference to a 
"free" function as attribute in an object. You can store a reference to a 
"bound" memberfunction outside the object and call it.

Objects and classes here are much more flexible than in C++ or Java.

Uli

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


Re: Style question: Nicknames for deeply nested objects

2011-01-30 Thread Ian

On 30/01/2011 17:51, Gerald Britton wrote:

Hi all,

Today I was thinking about a problem I often encounter.  Say that I
have (seems I often do!) a deeply nested object, by which I mean
object within object with object, etc.

For example:

x = some.deeply.nested.object.method(some.other.deeply.nested.object.value)

Well, that's extreme but I've worked with code approaching that level
of nested-ness.  Now, consider two scenarios:

1. You need to call this thing many times with different arguments, so
you wind up with:

x = some.deeply.nested.object.method(some.other.deeply.nested.object.value1)
y = some.deeply.nested.object.method(some.other.deeply.nested.object.value2)
z = some.deeply.nested.object.method(some.other.deeply.nested.object.value3)


Neither.  You should tell. Don't ask if you can avoid it.

Compare...

queen.getButter()

and
queen.dairymaid.alderney.getButter()

see  http://www.timelessteacherstuff.com/readerstheater/KingsBreakfast.pdf

king doesn't care where or how the butter is brought.  Neither should 
your code!


What are you doing with value1, value2 and value3 when you have them 
anyway? Stuffing them 3 levels deep into something else?


Stop writing procedural code, and write object oriented code instead!

If you you make some tell  deeply.nested.object  about 
other.deeply.nested.object it can fetch its own values, but it might be 
better
to have some tell other.deeply.nested.object about deeply.nested.object 
to it can issue the correct commands.


Then you tell some to  do Somthing by writing

  some.takeMeaningfullAction()

and it all happens "under the covers".

Regards

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


homedir, file copy

2011-01-30 Thread ecu_jon
hello,
i am trying to work with windows homedirectory as a starting point for
some kind of file copy command. i'm testing this on a win7 box so my
home is c:\Users\jon\
here is the code snippet i am working on:

import os

homedir = os.path.expanduser('~')
try:
from win32com.shell import shellcon, shell
homedir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)

except ImportError:
homedir = os.path.expanduser("~")
print homedir
print os.listdir(homedir+"\\backup\\")
homedir.replace("" , "\\")
print homedir
shutil.copy (homedir+"\\backup\\", homedir+"\\backup2\\")


output looks like:
C:\Users\jon
['test1.txt', 'test2.txt']
C:\Users\jon

Traceback (most recent call last):
  File "D:\spring 11\capstone-project\date.py", line 43, in 
shutil.copy (homedir+"\\backup\\", homedir+"\\backup2\\")
  File "C:\Python27\lib\shutil.py", line 116, in copy
copyfile(src, dst)
  File "C:\Python27\lib\shutil.py", line 81, in copyfile
with open(src, 'rb') as fsrc:
IOError: [Errno 2] No such file or directory: 'C:\\Users\\jon\\backup\
\'


why is there still two \\ in the pathfor the copy command?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: homedir, file copy

2011-01-30 Thread r
On Jan 30, 2:44 pm, ecu_jon  wrote:

> shutil.copy (homedir+"\\backup\\", homedir+"\\backup2\\")

TIP: Use os.path.join(x,y, z*)

> why is there still two \\ in the pathfor the copy command?

I always convert my paths to use a single '/' instead of '\\'. Just
makes life that much easier!

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


Re: homedir, file copy

2011-01-30 Thread Chris Rebert
On Sun, Jan 30, 2011 at 12:44 PM, ecu_jon  wrote:
> hello,
> i am trying to work with windows homedirectory as a starting point for
> some kind of file copy command. i'm testing this on a win7 box so my
> home is c:\Users\jon\
> here is the code snippet i am working on:
>
> import os
>
> homedir = os.path.expanduser('~')
> try:
>    from win32com.shell import shellcon, shell
>    homedir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)
>
> except ImportError:
>    homedir = os.path.expanduser("~")
> print homedir
> print os.listdir(homedir+"\\backup\\")
> homedir.replace("" , "\\")
> print homedir
> shutil.copy (homedir+"\\backup\\", homedir+"\\backup2\\")
>
>
> output looks like:
> C:\Users\jon
> ['test1.txt', 'test2.txt']
> C:\Users\jon
>
> Traceback (most recent call last):
>  File "D:\spring 11\capstone-project\date.py", line 43, in 
>    shutil.copy (homedir+"\\backup\\", homedir+"\\backup2\\")
>  File "C:\Python27\lib\shutil.py", line 116, in copy
>    copyfile(src, dst)
>  File "C:\Python27\lib\shutil.py", line 81, in copyfile
>    with open(src, 'rb') as fsrc:
> IOError: [Errno 2] No such file or directory: 'C:\\Users\\jon\\backup\
> \'
>
>
> why is there still two \\ in the pathfor the copy command?

There aren't. The error message is just showing the repr() of the
string, which involves escaping any literal backslashes in it; note
the quotes around the path in the error message.
Details on repr(): http://docs.python.org/library/functions.html#repr

By way of example:
>>> x = raw_input()
C:\foo\bar
>>> print x
C:\foo\bar
>>> print repr(x)
'C:\\foo\\bar'
>>> print('C:\\foo\\bar')
C:\foo\bar

Note that you can use forward slashes instead of backslashes in
Windows paths in Python, thus avoiding this confusion altogether.

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


Re: Style question: Nicknames for deeply nested objects

2011-01-30 Thread rantingrick
On Jan 30, 12:53 pm, Stephen Hansen  wrote:
> On 1/30/11 10:35 AM, rantingrick wrote:
>
> > Well congratulations Stephen, you win the obfuscation prize of the
> > year!
>
> Yes,
>
> On 1/30/11 10:09 AM, rantingrick wrote:
>
> > Here is how a pythonic local block would look
>
> > with this as localvar:
> >     localvar.do_something()
>
> verses
>
> with my(this) as localvar:
>     localvar.do_something()
>
> Is dreadfully more, er, obfuscated.

Absolutely!

> I mean someone would have to know what the 'my' function does to
> understand what's going on!

Yes, and also how decorators word and generators work, and ...

> OH MY GOD. How can someone be expected to understand what a function does!

Yes, and also how decorators word and generators work, and ...

> Be serious! You can't expect that of them.

I don't. I don't expect anyone to write 10 lines of obfuscation code
when just two will suffice. Maybe you should join the perl group as
they would proud!

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


Re: Style question: Nicknames for deeply nested objects

2011-01-30 Thread Jerry Hill
>
> I don't. I don't expect anyone to write 10 lines of obfuscation code
> when just two will suffice. Maybe you should join the perl group as
> they would proud!


But Stephen's 10 lines of somewhat obscure code actually works, and your two
lines of code doesn't.  I know which one I would prefer.

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


Re: Style question: Nicknames for deeply nested objects

2011-01-30 Thread Steven D'Aprano
On Sun, 30 Jan 2011 12:51:20 -0500, Gerald Britton wrote:

> Hi all,
> 
> Today I was thinking about a problem I often encounter.  Say that I have
> (seems I often do!) a deeply nested object, by which I mean object
> within object with object, etc.
> 
> For example:
> 
>    x =
>    some.deeply.nested.object.method
(some.other.deeply.nested.object.value)
> 
> Well, that's extreme but I've worked with code approaching that level of
> nested-ness.

Then you're probably living in a state of sin, programming-wise, and you 
should stop doing that! You are violating the Law of Demeter. One dot, 
good. Two, acceptable. Three is a code smell. Four is a code reek.

The Law of Demeter (more of a guideline than a law, really) says:

If you want to get your dog to walk, call the dog. Don't talk to its 
legs, it confuses the dog and doesn't get it anywhere.

http://en.wikipedia.org/wiki/Law_of_Demeter

Another analogy: if you have to pay the paperboy for delivering the 
newspaper, you don't let him reach into your pocket, take out your 
wallet, open the wallet, take out whatever money he feels like, and put 
the wallet back.

http://www.ccs.neu.edu/research/demeter/demeter-method/LawOfDemeter/paper-
boy/demeter.pdf


Despite my comment above, the Law of Demeter is not *really* a dot-
counting exercise, although that's a handy short-cut for detecting 
potential problems. It can also apply to other data structures. If you've 
every seen C or Pascal code where you have a pointer to a pointer to a 
pointer to a pointer to a pointer to a pointer to some data, you've seen 
a violation.

Consider your example:

some.other.deeply.nested.object.value

This is very tightly coupled code: the caller, who knows about the object 
`some`, needs to know the internal details of not just `some` but also 
`other`, `deeply`, `nested`, and `object`. As a basic principle, this is 
poor design! Which would you rather deal with?

car.start()

car.ignition.turn(key).connect(car.starter(battery), car.spark_plug)

In particular, using temporary variables merely disguises the problem:

temp = some.other
temp = temp.deeply.nested
x = temp.object.value

Even though you never use more than two dots, you still have tight 
coupling. The point of Demeter is not to save dots (they're a renewable 
resource) but to reduce tight coupling.


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


Re: WxPython versus Tkinter.

2011-01-30 Thread Littlefield, Tyler
>Are you a representative voice for all the screen reader users? (Even 
though

>most of them use JAWS that you don't seem to like)
Newsflash: I didn't say I didn't like Jaws, and I'm using Jaws -right 
now-. I don't like jaws and see a lot of future for NVDA as it is both 
free and open source. I like that a lot more than paying what, $1300 or 
so for a program that will allow me to use the computer? Plus the 
obligatory $260 for two updates so I can update once every four months, 
regardless of whether or not I want to update. If you want to rant and 
scream about accessibility, yell at the people charging an arm and a leg 
to make things accessible.

On 1/28/2011 1:33 AM, Octavian Rasnita wrote:

From: "Littlefield, Tyler" 

>* Disclaimer: You are stupid if you think this is true. But seriously,
>Octavian makes it REALLY hard to continue caring about something that I
>actually cared about before and thought was important.


When I told about what the community of the blind from my country 
cares, or
what I care, the others told me that that is not important. I am sure 
that
won't say the same thing to your post in which you also say about what 
you

care, just because you have the same opinions like them.


People like Octavian do that. Sadly, it is one of the things holding the
blind community back. I hope that with my arguments (for those that 
didn't

just toss everything related to this thread), I have been able to get
people to see a little differently and not consider Octavian as the 
voice

for us all.



Who are those "us all"?
Are you a representative voice for all the screen reader users? (Even 
though

most of them use JAWS that you don't seem to like)
Or do you agree with the associations of the blind in your country do 
when
they fight with different companies because they make discrimination 
by not

offering accessible products?
Or you are more representative than those associations?

Octavian




--

Thanks,
Ty

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


Re: Understanding def foo(*args)

2011-01-30 Thread Ben Finney
sl33k_  writes:

> I am struggling to grasp this concept about def foo(*args). Also, what
> is def bar(*args, *kwargs)?

Please work through the Python Tutorial from start to finish
http://docs.python.org/tutorial/>, performing each exercise and
experimenting with it until you understand. You will then have a good
grounding in basics of the language like this.

-- 
 \ Lucifer: “Just sign the Contract, sir, and the Piano is yours.” |
  `\ Ray: “Sheesh! This is long! Mind if I sign it now and read it |
_o__)later?” —http://www.achewood.com/ |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: homedir, file copy

2011-01-30 Thread ecu_jon
On Jan 30, 3:55 pm, r  wrote:
> On Jan 30, 2:44 pm, ecu_jon  wrote:
>
> > shutil.copy (homedir+"\\backup\\", homedir+"\\backup2\\")
>
> TIP: Use os.path.join(x,y, z*)
>
> > why is there still two \\ in the pathfor the copy command?
>
> I always convert my paths to use a single '/' instead of '\\'. Just
> makes life that much easier!

what does this mean?  Use os.path.join(x,y, z*)
what is the x,y,z?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: homedir, file copy

2011-01-30 Thread Chris Rebert
On Sun, Jan 30, 2011 at 3:13 PM, ecu_jon  wrote:
> On Jan 30, 3:55 pm, r  wrote:
>> On Jan 30, 2:44 pm, ecu_jon  wrote:
>>
>> > shutil.copy (homedir+"\\backup\\", homedir+"\\backup2\\")
>>
>> TIP: Use os.path.join(x,y, z*)
>>
>> > why is there still two \\ in the pathfor the copy command?
>>
>> I always convert my paths to use a single '/' instead of '\\'. Just
>> makes life that much easier!
>
> what does this mean?  Use os.path.join(x,y, z*)
> what is the x,y,z?

See http://docs.python.org/library/os.path.html#os.path.join
e.g. in your case:
backupdir = os.path.join(homedir, "backup")

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


Re: homedir, file copy

2011-01-30 Thread rantingrick
On Jan 30, 5:13 pm, ecu_jon  wrote:

> what does this mean?  Use os.path.join(x,y, z*)
> what is the x,y,z?

x,y, and z in this case are just generic variables. Consider x+y=10. x
and y could both equal 5 or any number of combinations of two numbers
who sum equals ten. Anyway see the link chris posted to the docs or
fire up your python shell and try this...


>>> import sys
>>> sys.version_info
(2, 6, 5, 'final', 0) # yours may be different!
>>> folder = 'C:/somepath/to/folder'
>>> filename = 'somefile.txt'
>>> import os
>>> help(os.path.join)
Help on function join in module ntpath:

join(a, *p)
Join two or more pathname components, inserting "\" as needed.
If any component is an absolute path, all previous path components
will be discarded.

>>> os.path.join(folder, filename)
'C:/somepath/to/folder\\somefile.txt'
>>> help(os.path.normpath)
Help on function normpath in module ntpath:

normpath(path)
Normalize path, eliminating double slashes, etc.

>>> os.path.normpath(os.path.join(folder, filename))
'C:\\some\\path\\to\\folder\\somefile.txt'

psst: i know what you're thinking... and yes, python is very cool!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: homedir, file copy

2011-01-30 Thread ecu_jon
ok now i get permission denied

import os
homedir = os.path.expanduser('~')
try:
from win32com.shell import shellcon, shell
homedir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)

except ImportError:
homedir = os.path.expanduser("~")
print homedir
print os.listdir(homedir+"\\backup\\")
#homedir.replace("" , "\\")
#print homedir
backupdir1 = os.path.join(homedir, "backup")
backupdir2 = os.path.join(homedir, "backup2")
shutil.copy (backupdir1, backupdir2)

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


Re: WxPython versus Tkinter.

2011-01-30 Thread rantingrick
On Jan 28, 9:15 am, "Littlefield, Tyler"  wrote:
>
> If you want to rant and scream about accessibility, yell at the
> people charging an arm and a leg to make things accessible.
>

You make a good point as we could always use more opensource, free,
and reasonably priced software. However unless the GUI library in
question supports accessibility, it really won't matter how much the
tool costs if you cannot use it! Consider if automobiles were free
however gasoline was obsolete.

-- rr: spreading common sense like an incurable virus.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: homedir, file copy

2011-01-30 Thread MRAB

On 30/01/2011 23:43, ecu_jon wrote:

ok now i get permission denied

import os
homedir = os.path.expanduser('~')
try:
 from win32com.shell import shellcon, shell
 homedir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)

except ImportError:
 homedir = os.path.expanduser("~")
print homedir
print os.listdir(homedir+"\\backup\\")
#homedir.replace("" , "\\")
#print homedir
backupdir1 = os.path.join(homedir, "backup")
backupdir2 = os.path.join(homedir, "backup2")
shutil.copy (backupdir1, backupdir2)


shutil.copy(...) copies files, not directories. You should use
shutil.copytree(...) instead.
--
http://mail.python.org/mailman/listinfo/python-list


Re: homedir, file copy

2011-01-30 Thread ecu_jon
On Jan 30, 7:09 pm, MRAB  wrote:
> On 30/01/2011 23:43, ecu_jon wrote:
>
> > ok now i get permission denied
>
> > import os
> > homedir = os.path.expanduser('~')
> > try:
> >      from win32com.shell import shellcon, shell
> >      homedir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)
>
> > except ImportError:
> >      homedir = os.path.expanduser("~")
> > print homedir
> > print os.listdir(homedir+"\\backup\\")
> > #homedir.replace("" , "\\")
> > #print homedir
> > backupdir1 = os.path.join(homedir, "backup")
> > backupdir2 = os.path.join(homedir, "backup2")
> > shutil.copy (backupdir1, backupdir2)
>
> shutil.copy(...) copies files, not directories. You should use
> shutil.copytree(...) instead.

i will, closer towards the end.
just wanted to get past the naming stuff, the problem above.
right now i just want to see it move files from 1 place to another.
i had copytree in before, and will go back to that for final version.
im working on a backup program, and copytree looks yummy.

still no idea why getting permission denied.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: homedir, file copy

2011-01-30 Thread Dave Angel

On 01/-10/-28163 02:59 PM, ecu_jon wrote:

ok now i get permission denied

import os
homedir = os.path.expanduser('~')
try:
 from win32com.shell import shellcon, shell
 homedir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)

except ImportError:
 homedir = os.path.expanduser("~")
print homedir
print os.listdir(homedir+"\\backup\\")
#homedir.replace("" , "\\")
#print homedir
backupdir1 = os.path.join(homedir, "backup")
backupdir2 = os.path.join(homedir, "backup2")
shutil.copy (backupdir1, backupdir2)


You forgot to include the error traceback.

So, is homedir/backup a file, or is it a directory?  If you're trying to 
copy whole directories, you might want to look at copytree instead.


If you're not sure, you could use
os.isfile()

to check.  If that's false, then shutil.copy() can't work.  Similarly, 
if the destination is a readonly file, you'd get some error.


DaveA



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


MS Access table values as input into a formula in another table-need help!!

2011-01-30 Thread Cathy James
Dear Python Community,

Table1:
Prop_codeR_Value
GC 0.8
CI 0.6
LDR 0.4
HDR 0.6
TR 0.65
CR 0.35

Table 2:
O_ID PROP_CODE AI  TArea  R_Value Pre_R_Value IR
MER02006 LDR 38.19235 132.3178 0.4 0.115456 0.555143
MER02006 TR 20.78983 132.3178 0.65 0.102128 0.555143
MER02006 UO 1.850129 132.3178 0.25 0.003496 0.555143
MER03001 GC 16.565  137.592  0.8 0.096314 0.45027
Initially, I manually entered R_Value from table 1 into table 2 in order to
later compute subsequent fields using Python. Now I’d like to make the
process a bit more automatic. I would like to get R_Values  for each
Prop_Code  from table 1 into table 2 so that I can use them in a Table2
computation later on. I was thinking maybe a putting table 1 into a dict
then use those values in table 2, but I need help getting started. Just
learning Python and dicts are still tricky for me. Please help me modify the
code below so that i don't have to repeat the lines of code below for all
values of Prop_Code:
import arcpy,sys
arcpy.env.workspace = "C:\\test\\DRAINAGE.mdb"
Table1= "basins"
Table2="CV_Table"
cur = arcpy.UpdateCursor(table2, "[PROP_CODE] = 'LDR'")
row = cur.next()
# Perform the update and move to the next row as long as there are
#  rows left
while row:
row.R_Value  = 0 #initialize field from nulls to zero values
row.R_Value = 0.4 #INstead, I need to get this from Table 2
cur.updateRow(row)
row = cur.next()
# Delete the cursors to remove any data locks
del row, cur

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


Re: homedir, file copy

2011-01-30 Thread ecu_jon
On Jan 30, 7:19 pm, Dave Angel  wrote:
> On 01/-10/-28163 02:59 PM, ecu_jon wrote:
>
> > ok now i get permission denied
>
> > import os
> > homedir = os.path.expanduser('~')
> > try:
> >      from win32com.shell import shellcon, shell
> >      homedir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)
>
> > except ImportError:
> >      homedir = os.path.expanduser("~")
> > print homedir
> > print os.listdir(homedir+"\\backup\\")
> > #homedir.replace("" , "\\")
> > #print homedir
> > backupdir1 = os.path.join(homedir, "backup")
> > backupdir2 = os.path.join(homedir, "backup2")
> > shutil.copy (backupdir1, backupdir2)
>
> You forgot to include the error traceback.
>
> So, is homedir/backup a file, or is it a directory?  If you're trying to
> copy whole directories, you might want to look at copytree instead.
>
> If you're not sure, you could use
>      os.isfile()
>
> to check.  If that's false, then shutil.copy() can't work.  Similarly,
> if the destination is a readonly file, you'd get some error.
>
> DaveA

today's date is :  30
week chosen is :  4
C:\Users\jon
['test1.txt', 'test2.txt']

Traceback (most recent call last):
  File "D:\spring 11\capstone-project\date.py", line 45, in 
shutil.copy (backupdir1, backupdir2)
  File "C:\Python27\lib\shutil.py", line 116, in copy
copyfile(src, dst)
  File "C:\Python27\lib\shutil.py", line 81, in copyfile
with open(src, 'rb') as fsrc:
IOError: [Errno 13] Permission denied: 'C:\\Users\\jon\\backup'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: homedir, file copy

2011-01-30 Thread rantingrick
On Jan 30, 5:43 pm, ecu_jon  wrote:
> ok now i get permission denied

[...]

> shutil.copy (backupdir1, backupdir2)

I must stress the importance of proper testing before ever running
code that manipulates files! So many things can go wrong. Of course
you are just copying files here and not deleting them however you must
always be in the habit of treating files like explosives. And frankly
you're being quite nonchalant with this very naive approach to coding
and complete lack of testing.

When handling files always test, test, test. Never actually move,
copy, or delete until you are *absolutely* sure no failures will
occur. I will always do test runs that print out the action but DO NOT
actually DO the action, like...

Copying files:
 -- from: C:\\somefile1
  to: C:\\blah\\somefile1
 -- from: C:\\somefile2
  to: C:\\blah\\somefile2
 -- from: C:\\somefile3
  to: C:\\blah\\somefile3
 -- etc...

Once my test runs are bug free i can try to move or delete *one* file
from some test set. Once that is bug free then i will try the code on
many files of a test set, and ONLY THEN on the real thing. I guarantee
if you keep manipulating files in such a haphazard way you will live
to regret it!



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


Re: homedir, file copy

2011-01-30 Thread ecu_jon
On Jan 30, 7:34 pm, rantingrick  wrote:
> On Jan 30, 5:43 pm, ecu_jon  wrote:
>
> > ok now i get permission denied
>
> [...]
>
> > shutil.copy (backupdir1, backupdir2)
>
> I must stress the importance of proper testing before ever running
> code that manipulates files! So many things can go wrong. Of course
> you are just copying files here and not deleting them however you must
> always be in the habit of treating files like explosives. And frankly
> you're being quite nonchalant with this very naive approach to coding
> and complete lack of testing.
>
> When handling files always test, test, test. Never actually move,
> copy, or delete until you are *absolutely* sure no failures will
> occur. I will always do test runs that print out the action but DO NOT
> actually DO the action, like...
>
> Copying files:
>  -- from: C:\\somefile1
>       to: C:\\blah\\somefile1
>  -- from: C:\\somefile2
>       to: C:\\blah\\somefile2
>  -- from: C:\\somefile3
>       to: C:\\blah\\somefile3
>  -- etc...
>
> Once my test runs are bug free i can try to move or delete *one* file
> from some test set. Once that is bug free then i will try the code on
> many files of a test set, and ONLY THEN on the real thing. I guarantee
> if you keep manipulating files in such a haphazard way you will live
> to regret it!

not nonchalant.
i know i will ned to do testing and whatnot.
just personally, i like to build stuff one concept at a time.
for example, i had a problem with the homedir and peopel here helped
me with that.
now i have permissions problem, and an swer will likely meeerge.
once i know how to copy a file, ill work on testing. like isfile and
permissions.
i know that has to be done. i guess its that you want tests before
moves , and thats fine.
since i have only ever had 1 python class, and basically learning this
whole thing from scratch, i need to do things 1 step at a time.
so now any thoughts on why i cannot write to my own homedir?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: homedir, file copy

2011-01-30 Thread Westley Martínez
It seems like you are trying to copy directories with shutil.copy. Use
shutil.copytree instead.

On Sun, 2011-01-30 at 16:43 -0800, ecu_jon wrote:

> On Jan 30, 7:34 pm, rantingrick  wrote:
> > On Jan 30, 5:43 pm, ecu_jon  wrote:
> >
> > > ok now i get permission denied
> >
> > [...]
> >
> > > shutil.copy (backupdir1, backupdir2)
> >
> > I must stress the importance of proper testing before ever running
> > code that manipulates files! So many things can go wrong. Of course
> > you are just copying files here and not deleting them however you must
> > always be in the habit of treating files like explosives. And frankly
> > you're being quite nonchalant with this very naive approach to coding
> > and complete lack of testing.
> >
> > When handling files always test, test, test. Never actually move,
> > copy, or delete until you are *absolutely* sure no failures will
> > occur. I will always do test runs that print out the action but DO NOT
> > actually DO the action, like...
> >
> > Copying files:
> >  -- from: C:\\somefile1
> >   to: C:\\blah\\somefile1
> >  -- from: C:\\somefile2
> >   to: C:\\blah\\somefile2
> >  -- from: C:\\somefile3
> >   to: C:\\blah\\somefile3
> >  -- etc...
> >
> > Once my test runs are bug free i can try to move or delete *one* file
> > from some test set. Once that is bug free then i will try the code on
> > many files of a test set, and ONLY THEN on the real thing. I guarantee
> > if you keep manipulating files in such a haphazard way you will live
> > to regret it!
> 
> not nonchalant.
> i know i will ned to do testing and whatnot.
> just personally, i like to build stuff one concept at a time.
> for example, i had a problem with the homedir and peopel here helped
> me with that.
> now i have permissions problem, and an swer will likely meeerge.
> once i know how to copy a file, ill work on testing. like isfile and
> permissions.
> i know that has to be done. i guess its that you want tests before
> moves , and thats fine.
> since i have only ever had 1 python class, and basically learning this
> whole thing from scratch, i need to do things 1 step at a time.
> so now any thoughts on why i cannot write to my own homedir?


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


Re: homedir, file copy

2011-01-30 Thread MRAB

On 31/01/2011 00:18, ecu_jon wrote:

On Jan 30, 7:09 pm, MRAB  wrote:

On 30/01/2011 23:43, ecu_jon wrote:


ok now i get permission denied



import os
homedir = os.path.expanduser('~')
try:
  from win32com.shell import shellcon, shell
  homedir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)



except ImportError:
  homedir = os.path.expanduser("~")
print homedir
print os.listdir(homedir+"\\backup\\")
#homedir.replace("" , "\\")
#print homedir
backupdir1 = os.path.join(homedir, "backup")
backupdir2 = os.path.join(homedir, "backup2")
shutil.copy (backupdir1, backupdir2)


shutil.copy(...) copies files, not directories. You should use
shutil.copytree(...) instead.


i will, closer towards the end.
just wanted to get past the naming stuff, the problem above.
right now i just want to see it move files from 1 place to another.
i had copytree in before, and will go back to that for final version.
im working on a backup program, and copytree looks yummy.

still no idea why getting permission denied.


The path given by backupdir1 is a directory, so you're trying to use
shutil.copy(...) to copy a directory.

The reason that it's complaining about permissions is that shutil.copy
is trying to open the source file (look at the traceback) so that it
can copy the file's contents, but it's not a file, it's a directory.

CPython is written in C, so it's probably the underlying C library
which is reporting it as a permissions problem instead of a "that's not
a file!" problem. :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to pass CSV Reader Object As Argument to another Python File ???

2011-01-30 Thread rusi
On Jan 30, 10:35 pm, rusi  wrote:
> On Jan 30, 6:31 pm, bansi  wrote:
> > Isn't it possible to implement your suggestion without installing
> > Visual C++ 2008 .
>
> http://code.google.com/p/pyodbc/wiki/Building#Windows

Well... This is what the official site says...
On second thoughts I wonder: Would it not be possible to compile python
+pyodbc from source and use gcc/ming for that? Someone who knows more
of the windows build process may say something about the issues
involved.
-- 
http://mail.python.org/mailman/listinfo/python-list


Limit on entries in dictionary data structure

2011-01-30 Thread Shruti Sanadhya
Hi,

I am running a script that uses dictionaries on Python 2.6.4 on Ubuntu 9.10.
I notice that my script crashes with a MemoryError when my dictionary
reaches 44739243th entry. My system has 3GB RAM (32-bit). I noticed that
changing the key or value types also did not help my code. For simplicity I
tried running this:

#BEGIN:python code
import sys
f={}
lsize=0
try:
for k in range(0,4*44739243):
f[k]=k
if sys.getsizeof(f) > lsize:
lsize = sys.getsizeof(f)
print k, lsize
except:
print k, lsize
raise
#END:python code

The code terminates with:
"Traceback (most recent call last):
  File "pydict-limit.py", line 6, in 
f[k]=k
MemoryError"

I have also tried running this on Ubuntu 9.10 with Python 2.6.6 with 3.5GB
RAM(32-bit) and a 64-bit LINUX cluster machine with 62GB RAM and Python 2.4.
On both these machines it crashed at entry 44739243. The size of the data
structure grows to 1.5GB. On another 64-bit cluster machine with 32GB RAM
and Python 2.6.6 it crashed at entry 178956970. In this case the size of the
data structure grew to 6GB.

Has anybody encountered this before? Can somebody suggest any fix for this?
I am trying to read some 10GB network traces into a hash table(hence
dictionary) and need constant time lookup. Clearly increasing the machine
RAM does not work. Any suggestions would be greatly appreciated.

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


Re: homedir, file copy

2011-01-30 Thread ecu_jon
On Jan 30, 8:25 pm, MRAB  wrote:
> On 31/01/2011 00:18, ecu_jon wrote:
>
>
>
> > On Jan 30, 7:09 pm, MRAB  wrote:
> >> On 30/01/2011 23:43, ecu_jon wrote:
>
> >>> ok now i get permission denied
>
> >>> import os
> >>> homedir = os.path.expanduser('~')
> >>> try:
> >>>       from win32com.shell import shellcon, shell
> >>>       homedir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)
>
> >>> except ImportError:
> >>>       homedir = os.path.expanduser("~")
> >>> print homedir
> >>> print os.listdir(homedir+"\\backup\\")
> >>> #homedir.replace("" , "\\")
> >>> #print homedir
> >>> backupdir1 = os.path.join(homedir, "backup")
> >>> backupdir2 = os.path.join(homedir, "backup2")
> >>> shutil.copy (backupdir1, backupdir2)
>
> >> shutil.copy(...) copies files, not directories. You should use
> >> shutil.copytree(...) instead.
>
> > i will, closer towards the end.
> > just wanted to get past the naming stuff, the problem above.
> > right now i just want to see it move files from 1 place to another.
> > i had copytree in before, and will go back to that for final version.
> > im working on a backup program, and copytree looks yummy.
>
> > still no idea why getting permission denied.
>
> The path given by backupdir1 is a directory, so you're trying to use
> shutil.copy(...) to copy a directory.
>
> The reason that it's complaining about permissions is that shutil.copy
> is trying to open the source file (look at the traceback) so that it
> can copy the file's contents, but it's not a file, it's a directory.
>
> CPython is written in C, so it's probably the underlying C library
> which is reporting it as a permissions problem instead of a "that's not
> a file!" problem. :-)

as for testing i was planning on using something like this
http://docs.python.org/library/shutil.html
scroll down to 10.10.1.1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Style question: Nicknames for deeply nested objects

2011-01-30 Thread Stephen Hansen
On 1/30/11 1:13 PM, rantingrick wrote:
> On Jan 30, 12:53 pm, Stephen Hansen  wrote:
>> OH MY GOD. How can someone be expected to understand what a function does!
> 
> Yes, and also how decorators word and generators work, and ...
> 
>> Be serious! You can't expect that of them.
> 
> I don't. I don't expect anyone to write 10 lines of obfuscation code
> when just two will suffice. Maybe you should join the perl group as
> they would proud!

Riiight.

"suffice" doesn't mean what you think it means. Generally, if something
suffices -- it actually, you know, ... works.

My four lines of setup can get put into a library and treated as a
recipe if they don't want to get into understanding generators or
decorators: then its two lines to use, and those two lines are exactly
like your two lines except for two little details:

  1. They add a function call to the syntax.
  2. They actually work.

The OP doesn't have to understand decorators or generators if he doesn't
want to: though I encourage him to do so, as they are beautiful and
elegant tools that can very clearly and concisely help solve a lot of
problems.

Now, me? I wouldn't use the recipe, as I originally said in my response.
I'd just use a local variable. But the OP didn't like that, and he
wanted some indenting and whitespace to clearly demarcate where he
intended to use the local. So I gave him a way to do that.

You gave him... uh, what was it again?

Oh, right.

Nothing.

As usual.

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/



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


Re: homedir, file copy

2011-01-30 Thread Dave Angel

On 01/-10/-28163 02:59 PM, ecu_jon wrote:

On Jan 30, 7:19 pm, Dave Angel  wrote:

On 01/-10/-28163 02:59 PM, ecu_jon wrote:


ok now i get permission denied



import os
homedir =s.path.expanduser('~')
try:
  from win32com.shell import shellcon, shell
  homedir =hell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)



except ImportError:
  homedir =s.path.expanduser("~")
print homedir
print os.listdir(homedir+"\\backup\\")
#homedir.replace("" , "\\")
#print homedir
backupdir1 =s.path.join(homedir, "backup")
backupdir2 =s.path.join(homedir, "backup2")
shutil.copy (backupdir1, backupdir2)


You forgot to include the error traceback.

So, is homedir/backup a file, or is it a directory?  If you're trying to
copy whole directories, you might want to look at copytree instead.

If you're not sure, you could use
  os.isfile()

to check.  If that's false, then shutil.copy() can't work.  Similarly,
if the destination is a readonly file, you'd get some error.

DaveA


today's date is :  30
week chosen is :  4
C:\Users\jon
['test1.txt', 'test2.txt']

Traceback (most recent call last):
   File "D:\spring 11\capstone-project\date.py", line 45, in
 shutil.copy (backupdir1, backupdir2)
   File "C:\Python27\lib\shutil.py", line 116, in copy
 copyfile(src, dst)
   File "C:\Python27\lib\shutil.py", line 81, in copyfile
 with open(src, 'rb') as fsrc:
IOError: [Errno 13] Permission denied: 'C:\\Users\\jon\\backup'



Good job, reading the first part of my message.  Now, why are you saying 
in other messages that it can't write to your home directory?  The error 
doesn't refer to your home directory, it refers to a file 
C:\Users\jon\backup which it can't read.


But as your program demonstrates, that's a directory not a file.  It's 
fine to use shutil.copy, but then you have to give it a source file to copy.


For example, C:\Users\jon\backup\test1.txt

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


Re: multiple values for keyword argument

2011-01-30 Thread Patty
Well - this is all timely email.  I just spent the day configuring my HP mini 
netbook running Windows 7 with all the right software based on recomendations 
from folks on this list, from the Python Tutor list and an email group of 
former colleagues where I spelled out exactly all the programming languages and 
stuff I ideally wanted.  It has been very enlightening and actually not so 
difficult!  Asking pays off!  And I made a few realizations - I had some 
misperceptions about some software packages and -- I had been thinking about 
this 'self' business since yesterday.  And you and Ethan and Ben Finney from 
yesterday (the last email msg I read last night, might know) are right -- I was 
being stubborn and wanting to do things *my* way and I was telling myself that 
when it comes time to do this for a future employer, well I will just change my 
code in the appropriate places to 'self' and will start using 'self' when I 
start working for them.  And a little thought  in the back of my head ... I 
wonder if the employer would be a little annoyed by that  :) 

OK - I need my hand slapped sometimes and I see that you all are trying to 
prevent me from developing a bad habit.  A few comments below:


"Steven D'Aprano"  wrote in message 
news:4d453127$0$29965$c3e8da3$54964...@news.astraweb.com...
> On Sat, 29 Jan 2011 10:39:49 -0800, patty wrote:
> 
>> I am glad you said this.  I have been avoiding understanding this
>> 'self', just accepting it :}  For the time being, since my programs I am
>> creating are for my own use, I think I will make my own names up, that
>> are descriptive to me as the programmer, it's all going to be
>> interpreted anyway.  And the other email equating to C's argv, etc. -
>> now I get it.
> 
> 
> That's a shame, because `self` is actually very simple once you 
> understand the basic principles of object-oriented programming.
> 
> What names would you choose? Unless you're writing descriptors, or using 
> class methods, both of which should be considered advanced usage (highly 
> advanced for descriptors, moderately so for class methods), it's not like 
> every method needs a different descriptive first argument. In English, 
> "self", "this", "me" or "instance" would be good names. What else would 
> you use?

That is the thing, I can get quite creative.  I envisioned myself giving it a 
name something like 'instancecalledfrommain'  probably scrunched up to 
'instfrmmain'
Weird descriptive names like that.  I keep thinking of it as a variable, so I 
keep thinking of what it is used for underlying its name.  Back to the 
I-can-do-anything-I-want
mindset.  

I have saved the messages in this thread and other ones from the last month or 
so about 'self' so I think I will gather them together and read them more 
carefully including your very good explanations below.


> 
> 
> The idea of method syntax is that you start with an instance of some 
> class:
> 
> mystring = "hello world"  # an instance of the str class
> 
> In procedural languages like C or Pascal, you would call a function and 
> give the string as an argument. Python supports this programming model, 
> and uses it for built-ins like len:
> 
> len(mystring)
> => returns 11
> 
> 

And I am more comfortable in the C and Pascal worlds as a base so I see why I 
go this direction.  



> Object oriented programming uses a different syntax. Instead of 
> 
> function(instance)
> 
> as above, we take the instance argument outside the brackets. For example:
> 
> mystring.upper()  # instead of upper(mystring)
> => returns "HELLO WORLD"
> 
> If there are any extra arguments needed, they go inside the brackets as 
> normal.
> 
> So far, this is just a change of syntax. It's like saying "The cat of my 
> brother's" vs. "my brother's cat" -- the meaning is the same, but the 
> syntax differs. 

And I am a linguist so now you are Really talking ;)



The real advantages of object oriented programming and 
> methods come elsewhere (e.g. encapsulation and inheritance).
> 
>[Aside: when I was learning this, the hardest part I found was
>remembering which things were functions, and which were methods. 
>I kept writing (wrongly!) things like:
> 
>"hello world".len()
>upper("hello world")
> 
>Unfortunately there is no easy way to recognise what will be a
>function like len, and which are methods like upper. That will 
>come with experience.

Oh!  I do this!  I seem to use this syntax interchangably.  I really need to 
memorize this carefully.


> 
> Back to function/procedural syntax versus object oriented syntax... 
> 
> One difference, though, is when you write a method definition. Because 
> the method you write starts off life as an ordinary function, you need to 
> write it *as if* it were a function you call like len() above. Here's how 
> you might write a method in a class:
> 
> class MyClass:
>def method(self, extra):
>pass
> 
> When you then call the method:
> 
> instance = MyClass()
> in

Re: Understanding def foo(*args)

2011-01-30 Thread rusi
On Jan 31, 12:35 am, rantingrick  wrote:
> > Also, can the terms method and function be used interchangeably?
>
> Can the terms cars and truck be used interchangeably?

Oooff! A load of meaning in that one line -- I wonder though if the OP
will understand...
-- 
http://mail.python.org/mailman/listinfo/python-list


Useing the processor clock, or get time in Femptoseconds

2011-01-30 Thread Garland Fulton
Does anyone have any suggestions?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Limit on entries in dictionary data structure

2011-01-30 Thread MRAB

On 31/01/2011 02:43, Shruti Sanadhya wrote:

Hi,

I am running a script that uses dictionaries on Python 2.6.4 on Ubuntu
9.10. I notice that my script crashes with a MemoryError when my
dictionary reaches 44739243th entry. My system has 3GB RAM (32-bit). I
noticed that changing the key or value types also did not help my code.
For simplicity I tried running this:

#BEGIN:python code
import sys
f={}
lsize=0
try:
 for k in range(0,4*44739243):
 f[k]=k
 if sys.getsizeof(f) > lsize:
 lsize = sys.getsizeof(f)
 print k, lsize
except:
 print k, lsize
 raise
#END:python code

The code terminates with:
"Traceback (most recent call last):
   File "pydict-limit.py", line 6, in 
 f[k]=k
MemoryError"

I have also tried running this on Ubuntu 9.10 with Python 2.6.6 with
3.5GB RAM(32-bit) and a 64-bit LINUX cluster machine with 62GB RAM and
Python 2.4. On both these machines it crashed at entry 44739243. The
size of the data structure grows to 1.5GB. On another 64-bit cluster
machine with 32GB RAM and Python 2.6.6 it crashed at entry 178956970. In
this case the size of the data structure grew to 6GB.

Has anybody encountered this before? Can somebody suggest any fix for
this? I am trying to read some 10GB network traces into a hash
table(hence dictionary) and need constant time lookup. Clearly
increasing the machine RAM does not work. Any suggestions would be
greatly appreciated.


sys.getsizeof(...) returns the size of an object itself, not the size
of an object plus any others which that object references.

The dict in your example code occupied 1.5GB, but that didn't include
the size of the int keys and values, only the references to them.

As for the 64-bit Linux cluster machine, did you run a 32-bit or a
64-bit build of Python? A 32-bit build can't use more than 4GB (2**32).
--
http://mail.python.org/mailman/listinfo/python-list


Re: Useing the processor clock, or get time in Femptoseconds

2011-01-30 Thread Littlefield, Tyler
If you are on windows, you can use high-resolution timers. What you are 
trying is physically impossible though: lets say you have a processor 
that runs at 2.5 GHz. that's 2.5 billion cycles per second, give or take 
a few. So, the lowest you can go is nanoseconds. You're trying to time 
like 10x the processor's actual speed, and you're not going to get 
timing that good. so, lower your bar a bit; the highest you will get is 
nanoseconds with high-res timers. (I'm not sure what the equivalent of 
this is on *nix, or whether or not python supports it on either 
platform. I think you'll end up making a DLL call, though I could be wrong).


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


Re: WxPython versus Tkinter.

2011-01-30 Thread alex23
rantingrick  wrote:
> To be honest, i would sacrifice all the functionality of
> wxWidgets if we could get pyGUI into the stdlib. Why? Well because
> pyGUI would be under OUR complete control.

"You" would need to contribute something other than bullshit and
vitriol in order to be able to use the word "our" in the way you do
here.

> *if* the community saw the potential that i see with pyGUI
> and wanted to seriously do some development to bring it into 3.0
> compliance i'll bet Greg *would* be interested

You can't even generate your _own_ code for this idea and yet you
somehow mystically know how other people will respond? Have you _ever_
been even _close_ to being able to do this? You seem genuinely angry
and shocked at times that we haven't embraced you as some kind of
messianic firebrand, which doesn't really say a lot for your ability
to gauge the responses & desires of others.

Maybe Greg's not a complete egotist like yourself, needing the
attention and constant fluffing you seem to demand before you'll even
begin to consider coding. Maybe pyGUI as is scratches his itch,
because rather than spending YEARS trying to offload work onto the
community he just coded up what he needed to actually get something
_done_, something other than masturbating over a library for its own
sake. Maybe he has no interest in 3.x but has no concern with
community submitted patches.

A patch - I should probably explain for your sake, rick - is a diff of
changes to a body of code allowing the project maintainer to integrate
user submitted bug fixes and feature additions. Pretty much most
project maintainers will accept them sans manifesto too.

This isn't about getting  your ego stroked. This isn't about which
language's dick is the longest because it has its own GUI. This is
about people with lives of their own making small contributions born
of necessity culminating in the further growth & evolution of a useful
piece of code.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Limit on entries in dictionary data structure

2011-01-30 Thread Dan Stromberg
On Sun, Jan 30, 2011 at 6:43 PM, Shruti Sanadhya  wrote:
> Hi,
> I am running a script that uses dictionaries on Python 2.6.4 on Ubuntu 9.10.
> I notice that my script crashes with a MemoryError when my dictionary
> reaches 44739243th entry. My system has 3GB RAM (32-bit). I noticed that
> changing the key or value types also did not help my code. For simplicity I
> tried running this:
> #BEGIN:python code
> import sys
> f={}
> lsize=0
> try:
>     for k in range(0,4*44739243):
>         f[k]=k
>         if sys.getsizeof(f) > lsize:
>             lsize = sys.getsizeof(f)
>             print k, lsize
> except:
>     print k, lsize
>     raise
> #END:python code
> The code terminates with:
> "Traceback (most recent call last):
>   File "pydict-limit.py", line 6, in 
>     f[k]=k
> MemoryError"
> I have also tried running this on Ubuntu 9.10 with Python 2.6.6 with 3.5GB
> RAM(32-bit) and a 64-bit LINUX cluster machine with 62GB RAM and Python 2.4.
> On both these machines it crashed at entry 44739243. The size of the data
> structure grows to 1.5GB. On another 64-bit cluster machine with 32GB RAM
> and Python 2.6.6 it crashed at entry 178956970. In this case the size of the
> data structure grew to 6GB.
> Has anybody encountered this before? Can somebody suggest any fix for this?
> I am trying to read some 10GB network traces into a hash table(hence
> dictionary) and need constant time lookup. Clearly increasing the machine
> RAM does not work. Any suggestions would be greatly appreciated.
> Thanks,
> Shruti

If you need strict controls over how much memory is used, you might be
better off with C or something.  Or Cython would give you a Pythonic
syntax with C's datastructures (as well as Python-style
datastructures, but that gets back into memory unpredictability).  On
an Ubuntu system, you can probably "man hcreate" to get some info on a
hash table accessible from C.

If you need a huge "dictionary", then using something like gdbm or
bsddb might be good, though I doubt these are constant time - they're
more like single-table databases, where the keys and values must all
be strings or serialized non-strings.  However, they should be fine
with huge dictionaries.  They have the advantage of providing a pretty
dictionary-like interface.  This almost certainly would not bump into
any memory limits, as they are disk-based.

If you really do need to keep things in RAM (VM), you might try this
module: http://stromberg.dnsalias.org/~strombrg/treap/ on one of your
64 bit systems, preferably with a recent cpython like 2.6 or 2.7 built
with a 64 bit compiler.  It too is not constant time, but it is
O(c*log(n)) with a small c, at the expense of a higher standard
deviation in write times compared to something like a red/black tree
(better average performance though).  This provides a very
dictionary-like interface.  It would implicitly store things sorted by
key, incidentally, though that may be unimportant in your application.
 This may or may not have the same memory issues as the dictionary -
and I'd be very interested in hearing whether they do or not.

You might also be able to read everything into a big list, then sort
it.  Then use the bisect module to do log(n) time lookups.  This does
not give a dictionary-like interface or constant time, but it doesn't
require anything outside of CPython's standard library.  It may or may
not have the same memory issues you were seeing with dictionaries.

Here's something based on your code above, that works with the
mentioned treap module.  I found that it required about 1 gig for each
10% of the numbers the code was trying to save - on a 32 bit, Ubuntu
10.10 system.  However, I have only 3 gig of RAM, so I terminated it
before it got to a memory error:

#!/usr/bin/python

import sys
import treap
f = treap.treap()
top = 4*44739243
try:
for k in xrange(0, top):
sys.stdout.write('%d %f%%\r' % (k, k * 100.0 / top))
f[k]=k
print
except:
print
raise
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Useing the processor clock, or get time in Femptoseconds

2011-01-30 Thread John Nagle

On 1/30/2011 8:14 PM, Littlefield, Tyler wrote:

If you are on windows, you can use high-resolution timers. What you are
trying is physically impossible though: lets say you have a processor
that runs at 2.5 GHz. that's 2.5 billion cycles per second, give or take
a few. So, the lowest you can go is nanoseconds. You're trying to time
like 10x the processor's actual speed, and you're not going to get
timing that good. so, lower your bar a bit; the highest you will get is
nanoseconds with high-res timers. (I'm not sure what the equivalent of
this is on *nix, or whether or not python supports it on either
platform. I think you'll end up making a DLL call, though I could be
wrong).


   On x86 CPUs since the Pentium, you can read the CPU's cycle counter,
which is incrementing once for each clock cycle, maybe every 300ps
or so on a current generation CPU.
See "http://en.wikipedia.org/wiki/Time_Stamp_Counter";

   You do not want to do this.  First, you're in Python, which is
interpreted; picosecond level timing resolution is orders of magnitude
finer than is meaningful at the Python source level. Second,
on multiprocessors, each CPU has its own cycle clock, and they're not
synchronized.  Third, on superscalar CPUs, reading of the clock may
occur out of order and be meaningless.

   In Python, just call "time.time()", which gets you a floating point
number with about 1ms resolution.

John Nagle


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


Re: Bugs/issues in tkinter.simpledialog!!

2011-01-30 Thread alex23
rantingrick  wrote:
> Actually i see you point but there is a good reason behind me bringing
> this up here. I want to bring to the attention of everyone how little
> interest there is for Tkinter.

Right. You have no interest in resolving this issue and instead want
to use it as more ammunition in your ongoing crusade. You even have
the gall to act _offended_ at Giampaolo's suggestion that you log the
bug, dumping your usual bullshit and vitriol on someone WHO HAS
ACTUALLY DONE THE SORT OF WORK YOU CONSTANTLY CLAIM YOU'RE GOING TO,
even though your every intention was to parade this issue around as if
it somehow validates your personal blend of crazy.

You're a class act, that's for sure.

> Agreed. However i would rather just write a patch, send it to some
> email and be done. Or just commit the changes myself.  This bug
> tracker is just bureaucracy at it's worst. You are making this process
> too hard and people are not going to get involved when they have to
> jump through 20 hoops just to patch three lines of freaking code!

Because complex distributed coding projects should be treated like
Wikipedia?

It must suck being such a genius and yet be unable to grapple with a
simple bug tracker...
-- 
http://mail.python.org/mailman/listinfo/python-list