Re: os.path.realpath(path) bug on win7 ?

2013-01-06 Thread iMath
在 2013年1月6日星期日UTC+8下午3时06分10秒,Chris Rebert写道:
> On Sat, Jan 5, 2013 at 10:55 PM, iMath <2281570...@qq.com> wrote:
> 
> >
> 
> > os.path.realpath(path)  bug on win7 ?
> 
> >
> 
> > Temp.link is a Symbolic link
> 
> > Its target location is C:\test\test1
> 
> > But
> 
> > >>> os.path.realpath(r'C:\Users\SAMSUNG\Temp.link\test2')
> 
> > 'C:\\Users\\SAMSUNG\\Temp.link\\test2'
> 
> >
> 
> > I thought the return value should be ' C:\\test\\test1\\test2'
> 
> >
> 
> > Is it a bug ? anyone can clear it to me ?
> 
> 
> 
> What does os.path.islink('C:/Users/SAMSUNG/Temp.link') report?
True
> 
> 
> 
> Cheers,
> 
> Chris

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


Re: __builtins__ in bpython

2013-01-06 Thread alex23
On Jan 6, 6:35 am, chaouche yacine  wrote:
> Hi. In the standard pytohon interpreter and in ipython, __builtins__ is a 
> module, but in bpython it's a dictionnary. Was it redefined ?

I'd say it's a result of however bpython works and this:

"By default, when in the __main__ module, __builtins__ is the built-in
module builtins; when in any other module, __builtins__ is an alias
for the dictionary of the builtins module itself. __builtins__ can be
set to a user-created dictionary to create a weak form of restricted
execution."

http://docs.python.org/3/reference/executionmodel.html#naming-and-binding

This is a guess, I've never used bpython, being really quite happy
with iPython. Your best bet would be to ask the bpython dev or log an
issue on its repository:

https://bitbucket.org/bobf/bpython/issues
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pygame - importing GL - very bad...

2013-01-06 Thread alex23
On Jan 6, 5:49 am, someone  wrote:
> I thought that python also used "true" pass-by-reference, although I
> haven't figured out exactly when I have this problem. I can just see
> that sometimes I get this problem and then I need to copy the variable,
> if I don't want the original data of the variable to be overwritten...

Generally I find it easier to call variables 'labels' or 'references';
you're not stashing a value into a slot, you're giving a name to an
object. So you're never really passing values around, just labels that
refer to an object.

The confusion kicks in because there are two types of object: mutable
and immutable. Mutable objects can change, immutable objects cannot.
Operations on an immutable object will return a _new_ immutable
object; the label used in an operation on an immutable object will
refer to the new object, any other references to the original object
will continue to refer to the original. Strings, numbers, tuples and
frozensets are all immutable built-in types.

>>> a = "alpha"
>>> b = a
>>> a = a + "bet"
>>> a
'alphabet'
>>> b
'alpha'

With immutable types, you're safe to pass them into a function, act on
them, and not have references in the outer scope reflect the change:

>>> def double(x): return x * 2
...
>>> a = "alpha"
>>> double(a)
'alphaalpha'
>>> a
'alpha'

Everything else, including user defined objects, tend to be mutable:

>>> a = dict(foo=1,bar=2)
>>> b = a
>>> a['foo'] = 99
>>> a
{'foo': 99, 'bar': 2}
>>> b
{'foo': 99, 'bar': 2}

With mutable objects, you're _always_ operating on the _same_ object
that everything is referring to, even when you pass it into a
different scope:

>>> def toggle_foo( x ): x['foo'] = not x['foo']
...
>>> a = dict(foo=True)
>>> toggle_foo(a)
>>> a
{'foo': False}

Note that the `toggle_foo` function doesn't return anything, nor is
the value of a re-assigned. The object that a refers to is passed into
`toggle_foo`, modified in place, and all references to it remain
pointing to the same, now modified object.

This is one of the big causes of unexpected behaviour to new Python
users, but as you get a better understanding of how Python's object
model works, you'll see it's really quite consistent and predictable.

There are a couple of ways you can ensure you're always working with a
copy of an object if you need to. For lists, the canonical way is:

>>> a = [1,2,3]
>>> b = a
>>> a = [1, 2, 3]
>>> b = a[:] # shallow copy of a
>>> b.append(99)
>>> b
[1, 2, 3, 99]
>>> a
[1, 2, 3]

`b = a[:]` uses slice notation to create a new list that contains
everything in the original list, from start to end. This is called a
"shallow" copy; `a` and `b` both refer to _different_ lists, but the
objects within are the _same_ objects. For numbers, this isn't
important, as they're immutable. For mutable objects, however, it's
something you need to bear in mind:

>>> a = [ [1,2], [3, 4] ] # list of lists
>>> b = a[:]
>>> b[0][0] = 99
>>> b
[[99, 2], [3, 4]]
>>> a
[[99, 2], [3, 4]]

So here, while `b` refers to copy of `a`, that copy contains the
_same_ list objects that `a` does, so any changes to the internal
lists will be reflected in both references, while any changes to `b`
itself won't be:

>>> b.append([5,6])
>>> b
[[99, 2], [3, 4], [5, 6]]
>>> a
[[99, 2], [3, 4]]

This is where the `copy` module comes to the rescue, providing a
shallow copy function `copy`, as well as `deepcopy` that makes copies
of all the objects within the object:

>>> import copy
>>> a = [ [1,2], [3, 4] ] # list of lists
>>> b = copy.deepcopy(a)
>>> b[0][0] = 99
>>> b
[[99, 2], [3, 4]]
>>> a
[[1, 2], [3, 4]]

If you plan on using the `copy` module, it's worthwhile readings it
docs, as there are some nuances to it that I'm glossing over here.
TBH, I don't recall every needing to use `copy` in my code.

Hope this helps bring consistency where you currently find confusion :)
-- 
http://mail.python.org/mailman/listinfo/python-list


How to modify this script?

2013-01-06 Thread Kurt Hansen

http://www.tuxradar.com/content/save-time-gedit-snippets:

To convert tab-separated text lines into a HTML-table:

$<
lines = $GEDIT_SELECTED_TEXT.split("\n");
output = '\n';

for line in lines:
output += '';

columns = line.split("\t");
for item in columns:
output += '' + item + ' '

output += '\n';

output += '';
return output
>

I would like to make a small modification (I'm not a programmer myself). 
Let's say I have these lines:


Price table
1  Green apple  $1
5  Green apples  $4
10  Green apples  $7

Since there's only one "field" in the first line, I want this output:

Price table

- insted of

Price table

How to? Thank you i advance.
--
Venlig hilsen
Kurt Hansen
--
http://mail.python.org/mailman/listinfo/python-list


Re: pygame - importing GL - very bad...

2013-01-06 Thread someone

On 01/06/2013 12:37 PM, alex23 wrote:

On Jan 6, 5:49 am, someone  wrote:

I thought that python also used "true" pass-by-reference, although I
haven't figured out exactly when I have this problem. I can just see
that sometimes I get this problem and then I need to copy the variable,
if I don't want the original data of the variable to be overwritten...


Generally I find it easier to call variables 'labels' or 'references';
you're not stashing a value into a slot, you're giving a name to an
object. So you're never really passing values around, just labels that
refer to an object.


Ok.


The confusion kicks in because there are two types of object: mutable
and immutable. Mutable objects can change, immutable objects cannot.


Yes, I've seen that described before.


Operations on an immutable object will return a _new_ immutable
object; the label used in an operation on an immutable object will
refer to the new object, any other references to the original object
will continue to refer to the original. Strings, numbers, tuples and
frozensets are all immutable built-in types.

 >>> a = "alpha"
 >>> b = a
 >>> a = a + "bet"
 >>> a
 'alphabet'
 >>> b
 'alpha'


Ok, I think I knew some of these things, however I didn't think so much 
about them before now.



With immutable types, you're safe to pass them into a function, act on
them, and not have references in the outer scope reflect the change:

 >>> def double(x): return x * 2
 ...
 >>> a = "alpha"
 >>> double(a)
 'alphaalpha'
 >>> a
 'alpha'


This is exactly what I've found out happens to me some times. Until now 
I've managed to fix my problems. But it's good to remember this thing 
with immutable vs. mutable types, which was something I didn't think 
much about before. I'll think about this difference in the future, thank 
you.



Everything else, including user defined objects, tend to be mutable:

 >>> a = dict(foo=1,bar=2)
 >>> b = a
 >>> a['foo'] = 99
 >>> a
 {'foo': 99, 'bar': 2}
 >>> b
 {'foo': 99, 'bar': 2}


Yes, I've noticed this a lot of times in my own coding...


With mutable objects, you're _always_ operating on the _same_ object
that everything is referring to, even when you pass it into a
different scope:

 >>> def toggle_foo( x ): x['foo'] = not x['foo']
 ...
 >>> a = dict(foo=True)
 >>> toggle_foo(a)
 >>> a
 {'foo': False}


Exactly, what I've also experienced a few times.


Note that the `toggle_foo` function doesn't return anything, nor is
the value of a re-assigned. The object that a refers to is passed into
`toggle_foo`, modified in place, and all references to it remain
pointing to the same, now modified object.


Yes, I notice that, thanks.


This is one of the big causes of unexpected behaviour to new Python
users, but as you get a better understanding of how Python's object
model works, you'll see it's really quite consistent and predictable.


It was a bit surprising to me in the beginning - though I'm still a 
beginner (or maybe now almost an "intermediate" user), the good 
explanation you come with now wasn't something I've thought so much of 
before now. But I've clearly experienced many of the examples you write 
about here, in my own coding and I've usually been very careful about 
checking if my original object was modified un-intentionally. I think I 
can deal with this now.



There are a couple of ways you can ensure you're always working with a
copy of an object if you need to. For lists, the canonical way is:

 >>> a = [1,2,3]
 >>> b = a
 >>> a = [1, 2, 3]
 >>> b = a[:] # shallow copy of a
 >>> b.append(99)
 >>> b
 [1, 2, 3, 99]
 >>> a
 [1, 2, 3]

`b = a[:]` uses slice notation to create a new list that contains
everything in the original list, from start to end. This is called a
"shallow" copy; `a` and `b` both refer to _different_ lists, but the
objects within are the _same_ objects. For numbers, this isn't


Ok, good to know.


important, as they're immutable. For mutable objects, however, it's
something you need to bear in mind:

 >>> a = [ [1,2], [3, 4] ] # list of lists
 >>> b = a[:]
 >>> b[0][0] = 99
 >>> b
 [[99, 2], [3, 4]]
 >>> a
 [[99, 2], [3, 4]]

So here, while `b` refers to copy of `a`, that copy contains the
_same_ list objects that `a` does, so any changes to the internal
lists will be reflected in both references, while any changes to `b`
itself won't be:

 >>> b.append([5,6])
 >>> b
 [[99, 2], [3, 4], [5, 6]]
 >>> a
 [[99, 2], [3, 4]]


Yes, I've experienced this kind of thing before - but it's a very very 
good explanation you give me know. It makes me understand the problem 
much better, next time I experience it...



This is where the `copy` module comes to the rescue, providing a
shallow copy function `copy`, as well as `deepcopy` that makes copies
of all the objects within the object:

 >>> import cop

Re: Good Python IDE

2013-01-06 Thread Tetsuya

On 01/06/2013 05:45 AM, Sourabh Mhaisekar wrote:

Hello All,
I am recently started couple of projects in Python, one in Python GTK

> and one in Python Qt. I want a good IDE (For Windows ) for Python which
> gives support for Python as well as PyGtk and PyQt.


Features I am looking for
* Support for Core Python Auto-completion.
* Support for PyGtk and PyQt
* Support for either Bazaar (preferred) or CVS

Thanks !

- Sourabh



I develop only under GNU/Linux (using Vim, with some plugins like 
python-jedi and supertab for autocompletion, Gundo for undo management 
in a *very* smart way, etc..), but in the recent past I tried various 
IDEs. They're all ugly and/or cumbersome, but it seemed to me that the 
less ugly maybe is PyCharm, you could try that.

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


Re: How to modify this script?

2013-01-06 Thread Chris Angelico
On Sun, Jan 6, 2013 at 11:42 PM, Kurt Hansen  wrote:
> Since there's only one "field" in the first line, I want this output:
>
> Price table
>
> - insted of
>
> Price table
>
> How to? Thank you i advance.

It's actually quite simple, as long as you don't mind the junk of
colspan="1" on all the other cells. Just replace the innermost loop
with:

for item in columns:
output += '' +
item + ' '

Untested, but it ought to work - as long as you never have _more_
cells in the line.

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


Re: How to modify this script?

2013-01-06 Thread chaouche yacine
if len(columns) != 3:
   colspan = 3 - len(columns) + 1
   output += '' % (colspan) + item + ' '

I did not test. Use with caution.





 From: Kurt Hansen 
To: python-list@python.org 
Sent: Sunday, January 6, 2013 1:42 PM
Subject: How to modify this script?
 
http://www.tuxradar.com/content/save-time-gedit-snippets:

To convert tab-separated text lines into a HTML-table:

$<
lines = $GEDIT_SELECTED_TEXT.split("\n");
output = '\n';

for line in lines:
    output += '';
    
    columns = line.split("\t");
    for item in columns:
        output += '' + item + ' '
    
    output += '\n';

output += '';
return output
>

I would like to make a small modification (I'm not a programmer myself). Let's 
say I have these lines:

Price table
1  Green apple  $1
5  Green apples  $4
10  Green apples  $7

Since there's only one "field" in the first line, I want this output:

Price table

- insted of

Price table

How to? Thank you i advance.
-- Venlig hilsen
Kurt Hansen
-- http://mail.python.org/mailman/listinfo/python-list-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Good Python IDE

2013-01-06 Thread Colin J. Williams

On 06/01/2013 7:48 AM, Tetsuya wrote:

On 01/06/2013 05:45 AM, Sourabh Mhaisekar wrote:

Hello All,
I am recently started couple of projects in Python, one in Python GTK

 > and one in Python Qt. I want a good IDE (For Windows ) for Python which
 > gives support for Python as well as PyGtk and PyQt.


Features I am looking for
* Support for Core Python Auto-completion.
* Support for PyGtk and PyQt
* Support for either Bazaar (preferred) or CVS

Thanks !

- Sourabh



I develop only under GNU/Linux (using Vim, with some plugins like
python-jedi and supertab for autocompletion, Gundo for undo management
in a *very* smart way, etc..), but in the recent past I tried various
IDEs. They're all ugly and/or cumbersome, but it seemed to me that the
less ugly maybe is PyCharm, you could try that.
I would suggest that you look at PyScripter for Windows or Linuz when 
Wine is available.


See: http://www.decalage.info/en/python/tutorial

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


Re: Proof that nobody reads the tests

2013-01-06 Thread Chris Angelico
On Mon, Jan 7, 2013 at 12:01 AM, chaouche yacine
 wrote:
> Has anybody read the source code of
> /usr/lib/python2.7/test/inspect_fodder.py ?
>
> I wonder how did they let this into the official python distribution. I
> thought Guido was serious :) people of the PSF seem to have a certain sense
> of humour.

I don't understand your comments. It's full of Monty Python
references; that's true of large slabs of Python code and
documentation.

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


Re: Proof that nobody reads the tests

2013-01-06 Thread chaouche yacine
Oh :) sorry I didn't know they were references to monty python sketches. That 
explains it then :)





 From: Chris Angelico 
To: python-list@python.org 
Sent: Sunday, January 6, 2013 2:14 PM
Subject: Re: Proof that nobody reads the tests
 
On Mon, Jan 7, 2013 at 12:01 AM, chaouche yacine
 wrote:
> Has anybody read the source code of
> /usr/lib/python2.7/test/inspect_fodder.py ?
>
> I wonder how did they let this into the official python distribution. I
> thought Guido was serious :) people of the PSF seem to have a certain sense
> of humour.

I don't understand your comments. It's full of Monty Python
references; that's true of large slabs of Python code and
documentation.

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


Re: Proof that nobody reads the tests

2013-01-06 Thread Chris Angelico
On Mon, Jan 7, 2013 at 12:26 AM, chaouche yacine
 wrote:
> Oh :) sorry I didn't know they were references to monty python sketches.
> That explains it then :)

Check out the Argument Clinic some time :)

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


Re: How to modify this script?

2013-01-06 Thread Kurt Hansen

Den 06/01/13 13.52, Chris Angelico skrev:

On Sun, Jan 6, 2013 at 11:42 PM, Kurt Hansen  wrote:

Since there's only one "field" in the first line, I want this output:

Price table

- insted of

Price table

How to? Thank you i advance.



It's actually quite simple, as long as you don't mind the junk of
colspan="1" on all the other cells.


I do, but I would like to test anyway ;-)

 Just replace the innermost loop

with:

 for item in columns:
 output += '' +
item + ' '


"innermost"? I have replaced this with yours, but all the marked text 
are deleted:


for item in columns:
output += '' + item + ' '


Untested, but it ought to work - as long as you never have _more_
cells in the line.

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


Ubuntu Python -dbg packages

2013-01-06 Thread Lee Harr

I am using:
Ubuntu 12.10
Python 3.2.3
Qt 4.8.2
PyQt 4.9.3
 
I also have the ubuntu -dbg packages:
python3-dbg
python3-pyqt4-dbg
 
 
 
I don't understand why python3-dbg cannot import the PyQt4 modules...
 
$ python3
Python 3.2.3 (default, Oct 19 2012, 19:53:57)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'/usr/bin/python3'
>>> import PyQt4
>>> import PyQt4.QtCore
>>>
 
 
$ python3-dbg
Python 3.2.3 (default, Oct 19 2012, 19:58:54)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
[60298 refs]
>>> sys.executable
'/usr/bin/python3-dbg'
[60300 refs]
>>> import PyQt4
[60323 refs]
>>> PyQt4.__file__
'/usr/lib/python3/dist-packages/PyQt4/__init__.py'
[60323 refs]
>>> import PyQt4.QtCore
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named QtCore
[150996 refs]
>>>
 
 
 
Also... The python3-pyqt4-dbg package seems to install to a different
location, so I tried inserting that dir on to sys.path with unexpected results.
 
$ python3-dbg
Python 3.2.3 (default, Oct 19 2012, 19:58:54)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
[60298 refs]
>>> sys.path.insert(1, '/usr/lib/debug/usr/lib/python3/dist-packages/')
[60299 refs]
>>> import PyQt4
[60335 refs]
>>> PyQt4.__file__
'/usr/lib/python3/dist-packages/PyQt4/__init__.py'
[60337 refs]
>>>
 
 
I noticed that there was no __init__.py in
/usr/lib/debug/usr/lib/python3/dist-packages/PyQt4
so I added that and then...
 
$ python3-dbg
Python 3.2.3 (default, Oct 19 2012, 19:58:54)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
[60298 refs]
>>> sys.path.insert(1, '/usr/lib/debug/usr/lib/python3/dist-packages')
[60299 refs]
>>> import PyQt4
[60324 refs]
>>> PyQt4.__file__
'/usr/lib/debug/usr/lib/python3/dist-packages/PyQt4/__init__.py'
[60328 refs]
>>> import PyQt4.QtCore
Segmentation fault (core dumped)
 
 
Clearly, I am doing something wrong.
 
Any hints?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to modify this script?

2013-01-06 Thread Kurt Hansen

Den 06/01/13 13.58, chaouche yacine skrev:

if len(columns) != 3:
colspan = 3 - len(columns) + 1
output += '' % (colspan) + item + ' '

I did not test. Use with caution.


I've tried to put it in several different places in the script, but with 
no luck; remember that I'm not experienced, so please tell me exactly 
where it's surposed to be inserted. Could you eventually show the 
complete modified script?





*From:* Kurt Hansen 
*To:* python-list@python.org
*Sent:* Sunday, January 6, 2013 1:42 PM
*Subject:* How to modify this script?

http://www.tuxradar.com/content/save-time-gedit-snippets:

To convert tab-separated text lines into a HTML-table:

$<
lines = $GEDIT_SELECTED_TEXT.split("\n");
output = '\n';

for line in lines:
 output += '';

 columns = line.split("\t");
 for item in columns:
 output += '' + item + ' '

 output += '\n';

output += '';
return output
 >

I would like to make a small modification (I'm not a programmer myself).
Let's say I have these lines:

Price table
1  Green apple  $1
5  Green apples  $4
10  Green apples  $7

Since there's only one "field" in the first line, I want this output:

Price table

- insted of

Price table

How to? Thank you i advance.
-- Venlig hilsen
Kurt Hansen
-- http://mail.python.org/mailman/listinfo/python-list





--
Venlig hilsen
Kurt Hansen
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to modify this script?

2013-01-06 Thread Chris Angelico
On Mon, Jan 7, 2013 at 12:34 AM, Kurt Hansen  wrote:
> "innermost"? I have replaced this with yours, but all the marked text are
> deleted:

Here's the full code, with my change:

$<
lines = $GEDIT_SELECTED_TEXT.split("\n");
output = '\n';

for line in lines:
output += '';

columns = line.split("\t");
for item in columns:
output += '' +
item + ' '

output += '\n';

output += '';
return output
>

It's only one line of code that needs to be changed. Python loops (and
other control structures) are defined by indentation, so the innermost
loop is the one that starts furthest to the right.

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


Newbie problem with Python pandas

2013-01-06 Thread RueTheDay
I'm working my way through the examples in the O'Reilly book Python For 
Data Analysis and have encountered a snag.

The following code is supposed to analyze some web server log data and 
produces aggregate counts by client operating system.

###
import json # used to process json records
from pandas import DataFrame, Series
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

path = '/home/rich/code/sample.txt'
records = [json.loads(line) for line in open(path)] #read in records one 
line at a time
frame = DataFrame(records)

cframe = frame[frame.a.notnull()]
operating_system = np.where(cframe['a'].str.contains
('Windows'),'Windows', 'Not Windows')
by_tz_os = cframe.groupby(['tz', operating_system])
agg_counts = by_tz_os.size().unstack().fillna(0)
indexer = agg_counts.sum(1).argsort()
count_subset = agg_counts.take(indexer)[-10:]
print count_subset


I am getting the following error when running on Python 2.7 on Ubuntu 
12.04:

>>
Traceback (most recent call last):
  File "./lp1.py", line 12, in 
operating_system = np.where(cframe['a'].str.contains
('Windows'),'Windows', 'Not Windows')
AttributeError: 'Series' object has no attribute 'str'
>>>

Note that I was able to get the code to work fine on Windows 7, so this 
appears to be specific to Linux.

A little Googling showed others have encountered this problem and 
suggested replacing the np.where with a find, as so:


operating_system = ['Windows' if a.find('Windows') > 0 else 'Not Windows' 
for a in cframe['a']]


This appears to solve the first problem, but then it fails on the next 
line with:


Traceback (most recent call last):
  File "./lp1.py", line 14, in 
by_tz_os = cframe.groupby(['tz', operating_system])
  File "/usr/lib/pymodules/python2.7/pandas/core/generic.py", line 133, 
in groupby
sort=sort)
  File "/usr/lib/pymodules/python2.7/pandas/core/groupby.py", line 522, 
in groupby
return klass(obj, by, **kwds)
  File "/usr/lib/pymodules/python2.7/pandas/core/groupby.py", line 115, 
in __init__
level=level, sort=sort)
  File "/usr/lib/pymodules/python2.7/pandas/core/groupby.py", line 705, 
in _get_groupings
ping = Grouping(group_axis, gpr, name=name, level=level, sort=sort)
  File "/usr/lib/pymodules/python2.7/pandas/core/groupby.py", line 600, 
in __init__
self.grouper = self.index.map(self.grouper)
  File "/usr/lib/pymodules/python2.7/pandas/core/index.py", line 591, in 
map
return self._arrmap(self.values, mapper)
  File "generated.pyx", line 1141, in pandas._tseries.arrmap_int64 
(pandas/src/tseries.c:40593)
TypeError: 'list' object is not callable
>

The problem looks to be with the pandas module and appears to be Linux-
specific.

Any ideas?  I'm pulling my hair out over this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to modify this script?

2013-01-06 Thread chaouche yacine


Well, I'm not answering your question since I am rewriting the script, because 
I prefer it this way :)

def addline(line):
    return "%s\n" % line

def addcolumn(item,nb_columns):
    if nb_columns != 3:
    return "%s" % (3 - nb_columns + 1, item)
    return "%s" % item

output = "\n"
for line in file("data.txt"):
    items = line.strip().split("\t")
    columns = ""
    for item in items :
    columns += addcolumn(item,len(items))
    output  += addline(columns)


output += ""
print output


printed

>>> 
Price table
1  Green apple  $1
5  Green apples  $4
10  Green apples  $7

>>> 





From: Kurt Hansen 
To: python-list@python.org 
Sent: Sunday, January 6, 2013 2:38 PM
Subject: Re: How to modify this script?

Den 06/01/13 13.58, chaouche yacine skrev:
> if len(columns) != 3:
>     colspan = 3 - len(columns) + 1
>     output += '' % (colspan) + item + ' '
>
> I did not test. Use with caution.

I've tried to put it in several different places in the script, but with 
no luck; remember that I'm not experienced, so please tell me exactly 
where it's surposed to be inserted. Could you eventually show the 
complete modified script?

>
> 
> *From:* Kurt Hansen 
> *To:* python-list@python.org
> *Sent:* Sunday, January 6, 2013 1:42 PM
> *Subject:* How to modify this script?
>
> http://www.tuxradar.com/content/save-time-gedit-snippets:
>
> To convert tab-separated text lines into a HTML-table:
>
> $<
> lines = $GEDIT_SELECTED_TEXT.split("\n");
> output = '\n';
>
> for line in lines:
>      output += '';
>
>      columns = line.split("\t");
>      for item in columns:
>          output += '' + item + ' '
>
>      output += '\n';
>
> output += '';
> return output
>  >
>
> I would like to make a small modification (I'm not a programmer myself).
> Let's say I have these lines:
>
> Price table
> 1  Green apple  $1
> 5  Green apples  $4
> 10  Green apples  $7
>
> Since there's only one "field" in the first line, I want this output:
>
> Price table
>
> - insted of
>
> Price table
>
> How to? Thank you i advance.
> -- Venlig hilsen
> Kurt Hansen
> -- http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
Venlig hilsen
Kurt Hansen
-- 
http://mail.python.org/mailman/listinfo/python-list-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to modify this script?

2013-01-06 Thread Kurt Hansen

Den 06/01/13 14.44, Chris Angelico wrote:

On Mon, Jan 7, 2013 at 12:34 AM, Kurt Hansen  wrote:

"innermost"? I have replaced this with yours, but all the marked text are
deleted:


Here's the full code, with my change:

$<
lines = $GEDIT_SELECTED_TEXT.split("\n");
output = '\n';


I'm sorry to bother you, Chris, but applying the snippet with your code 
in Gedit still just deletes the marked, tab-separated text in the editor.

--
Venlig hilsen
Kurt Hansen
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to modify this script?

2013-01-06 Thread Chris Angelico
On Mon, Jan 7, 2013 at 1:03 AM, Kurt Hansen  wrote:
> I'm sorry to bother you, Chris, but applying the snippet with your code in
> Gedit still just deletes the marked, tab-separated text in the editor.

Ah, whoops. That would be because I had a bug in the code (that's why
I commented that it was untested). Sorry about that! Here's a fixed
version:

$<
lines = $GEDIT_SELECTED_TEXT.split("\n");
output = '\n';

for line in lines:
output += '';

columns = line.split("\t");
for item in columns:
output += '' + item + ' '

output += '\n';

output += '';
return output
>


Note that it's a single line:

output += '' + item + ' '

If your newsreader (or my poster) wraps it, you'll need to unwrap that
line, otherwise you'll get an IndentError.

That version should work.

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


Re: Proof that nobody reads the tests

2013-01-06 Thread D'Arcy J.M. Cain
On Sun, 6 Jan 2013 05:26:19 -0800 (PST)
chaouche yacine  wrote:
> Oh :) sorry I didn't know they were references to monty python
> sketches. That explains it then :)

The name of the language itself is a reference to Monty Python.  That
is specifically what it was named after.

-- 
D'Arcy J.M. Cain  |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
IM: da...@vex.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to modify this script?

2013-01-06 Thread Kurt Hansen

Den 06/01/13 15.01, chaouche yacine wrote:

Well, I'm not answering your question since I am rewriting the script,
because I prefer it this way :)

def addline(line):
 return "%s\n" % line

[cut]

I surpose I shall put your code between $< and >?


printed

 >>> 
Price table
1  Green apple  $1
5  Green apples  $4
10  Green apples  $7

 >>>


Aha, so you tested it yourself?

When running this in Gedit on four lines of tab-separated text the 
output is:


%s\n" % line

def addcolumn(item,nb_columns):
if nb_columns != 3:
return "%s" % (3 - nb_columns + 1, item)
return "%s" % item

output = "\n"
for line in file("data.txt"):
items = line.strip().split("\t")
columns = ""
for item in items :
columns += addcolumn(item,len(items))
output  += addline(columns)


output += ""
print output
>
--
Venlig hilsen
Kurt Hansen
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to modify this script?

2013-01-06 Thread Subimal Deb
Kurt,
Try this:


$<
lines = $GEDIT_SELECTED_TEXT.split("\n");
output = '\n';

for line in lines:
output += '';

columns = line.split("\t");
if len(columns)==1:
output += '', line, ''
else:
for item in columns:
output += '' + item + ' '

output += '\n';

output += '';
return output
 > 


All I have done is to 
If there is one item in the tab-separated line : 
 print the line as a row spanning 3 columns
else:
 print the items in the line as an item in each column

I have not tried this snippet in Gedit - so use with caution. 

good luck,
Subimal Deb




On Sunday, January 6, 2013 6:12:11 PM UTC+5:30, Kurt Hansen wrote:
> http://www.tuxradar.com/content/save-time-gedit-snippets:
> 
> 
> 
> To convert tab-separated text lines into a HTML-table:
> 
> 
> 
> $<
> 
> lines = $GEDIT_SELECTED_TEXT.split("\n");
> 
> output = '\n';
> 
> 
> 
> for line in lines:
> 
>   output += '';
> 
>   
> 
>   columns = line.split("\t");
> 
>   for item in columns:
> 
>   output += '' + item + ' '
> 
>   
> 
>   output += '\n';
> 
> 
> 
> output += '';
> 
> return output
> 
>  >
> 
> 
> 
> I would like to make a small modification (I'm not a programmer myself). 
> 
> Let's say I have these lines:
> 
> 
> 
> Price table
> 
> 1  Green apple  $1
> 
> 5  Green apples  $4
> 
> 10  Green apples  $7
> 
> 
> 
> Since there's only one "field" in the first line, I want this output:
> 
> 
> 
> Price table
> 
> 
> 
> - insted of
> 
> 
> 
> Price table
> 
> 
> 
> How to? Thank you i advance.
> 
> -- 
> 
> Venlig hilsen
> 
> Kurt Hansen


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


Re: How to modify this script?

2013-01-06 Thread Kurt Hansen

Den 06/01/13 15.20, Chris Angelico wrote:

On Mon, Jan 7, 2013 at 1:03 AM, Kurt Hansen  wrote:

I'm sorry to bother you, Chris, but applying the snippet with your code in
Gedit still just deletes the marked, tab-separated text in the editor.



Ah, whoops. That would be because I had a bug in the code (that's why
I commented that it was untested). Sorry about that! Here's a fixed
version:


[cut]>

Note that it's a single line:

output += '' + item + ' '

If your newsreader (or my poster) wraps it, you'll need to unwrap that
line, otherwise you'll get an IndentError.


Ahhh, I did'nt realize that. Now it works :-)


That version should work.


It certainly does. I'll keep it and use it until at better solution is 
found. In the meantime I can just remove any unnecessary "colspan="1" 
with a macro.


Thanks for your help.
--
Venlig hilsen
Kurt Hansen
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to modify this script?

2013-01-06 Thread Chris Angelico
On Mon, Jan 7, 2013 at 1:30 AM, Kurt Hansen  wrote:
> Den 06/01/13 15.20, Chris Angelico wrote:
>
>> On Mon, Jan 7, 2013 at 1:03 AM, Kurt Hansen  wrote:
>>>
>>> I'm sorry to bother you, Chris, but applying the snippet with your code
>>> in
>>> Gedit still just deletes the marked, tab-separated text in the editor.
>
>
>> Ah, whoops. That would be because I had a bug in the code (that's why
>> I commented that it was untested). Sorry about that! Here's a fixed
>> version:
>>
> [cut]>
>
>> Note that it's a single line:
>>
>> output += '' + item + ' '
>>
>> If your newsreader (or my poster) wraps it, you'll need to unwrap that
>> line, otherwise you'll get an IndentError.
>
>
> Ahhh, I did'nt realize that. Now it works :-)
>
>> That version should work.
>
>
> It certainly does. I'll keep it and use it until at better solution is
> found. In the meantime I can just remove any unnecessary "colspan="1" with a
> macro.
>
> Thanks for your help.

Excellent! You'll find that Subimal's solution doesn't have those
colspan="1" lines, so take your pick as to which way you want to go.

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


Re: How to modify this script?

2013-01-06 Thread Kurt Hansen

Den 06/01/13 15.22, Subimal Deb wrote:

Kurt,
Try this:


[cut]

I've tested it on my original example:

Price table
1   Green apple $1
5   Green apples$4
10  Green apples$7

With all four lines selected it makes an error. With only three (without 
the first line) it works all right.


The error message says:

Execution of the Python command (lines = 'Price table\n1\tGreen 
apple\t$1\n5\tGreen apples\t$4\n10\tGreen apples\t$7'.split("\n");

output = '\n';

for line in lines:
output += '';

columns = line.split("\t");
if len(columns)==1:
output += '', line, ''
else:
for item in columns:
output += '' + item + ' '

output += '\n';

output += '';
return output) failed: cannot concatenate 'str' and 'tuple' objects
--
Venlig hilsen
Kurt Hansen
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to modify this script?

2013-01-06 Thread Chris Angelico
On Mon, Jan 7, 2013 at 1:40 AM, Kurt Hansen  wrote:
> failed: cannot concatenate 'str' and 'tuple' objects

The problem is this line:

output += '', line, ''

Change it to:

output += '' + line + ''

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


Re: How to modify this script?

2013-01-06 Thread Kurt Hansen

Den 06/01/13 15.52, Chris Angelico skrev:

On Mon, Jan 7, 2013 at 1:40 AM, Kurt Hansen  wrote:

failed: cannot concatenate 'str' and 'tuple' objects


The problem is this line:

output += '', line, ''

Change it to:

output += '' + line + ''


:-)

Something happened allright, but ...
Output with this change:

' + line + ''
else:
for item in columns:
output += '' + item + ' '

output += '\n';

output += '';
return output
>
--
Venlig hilsen
Kurt Hansen
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to modify this script?

2013-01-06 Thread chaouche yacine
I'm not confident this would run on gedit. It works on a python interpreter if 
you have a file named data.txt in the same directory containing your sample 
data.

It surely has to do with how gedit works then, because the "$" sign isn't used 
in python, this business should be a gedit convention. And sorry, I can't help 
on that, I'm not a user of gedit myself. Fortunately others have answered and I 
beleive one of the solutions worked for you.




 From: Kurt Hansen 
To: python-list@python.org 
Sent: Sunday, January 6, 2013 3:21 PM
Subject: Re: How to modify this script?
 
Den 06/01/13 15.01, chaouche yacine wrote:
> Well, I'm not answering your question since I am rewriting the script,
> because I prefer it this way :)
> 
> def addline(line):
>      return "%s\n" % line
[cut]

I surpose I shall put your code between $< and >?

> printed
> 
>  >>> 
> Price table
> 1  Green apple  $1
> 5  Green apples  $4
> 10  Green apples  $7
> 
>  >>>

Aha, so you tested it yourself?

When running this in Gedit on four lines of tab-separated text the output is:

%s\n" % line

def addcolumn(item,nb_columns):
    if nb_columns != 3:
        return "%s" % (3 - nb_columns + 1, item)
    return "%s" % item

output = "\n"
for line in file("data.txt"):
    items = line.strip().split("\t")
    columns = ""
    for item in items :
        columns += addcolumn(item,len(items))
    output  += addline(columns)


output += ""
print output
>
-- Venlig hilsen
Kurt Hansen
-- http://mail.python.org/mailman/listinfo/python-list-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Yet another attempt at a safe eval() call

2013-01-06 Thread Grant Edwards
On 2013-01-05, Oscar Benjamin  wrote:
> On 4 January 2013 15:53, Grant Edwards  wrote:
>> On 2013-01-04, Steven D'Aprano  wrote:
>>> On Thu, 03 Jan 2013 23:25:51 +, Grant Edwards wrote:
>>>
>>> * But frankly, you should avoid eval, and write your own mini-integer
>>>   arithmetic evaluator which avoids even the most remote possibility
>>>   of exploit.
>>
>> That's obviously the "right" thing to do.  I suppose I should figure
>> out how to use the ast module.
>
> Someone has already created a module that does this called numexpr. Is
> there some reason why you don't want to use that?

1) I didn't know about it, and my Googling didn't find it.

2) It's not part of the standard library, and my program needs to be
   distributed as a single source file.
   
-- 
Grant
-- 
http://mail.python.org/mailman/listinfo/python-list


Newbee question about running a script

2013-01-06 Thread marc.assin
Hello,

I've just installed Python 2.7 on Windows 7
I've been able to write and run a script "Hello world"
I wonder how I could specify a parameter on the command line from
within the interpreter.
Specifying a parameter on the DOS command line is no problem.

Any hint, please ?


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


Re: Newbie problem with Python pandas

2013-01-06 Thread Miki Tebeka
On Sunday, January 6, 2013 5:57:17 AM UTC-8, RueTheDay wrote:
> I am getting the following error when running on Python 2.7 on Ubuntu 
> 12.04:
> >>
>
> AttributeError: 'Series' object has no attribute 'str'
I would *guess* that  you have an older version of pandas on your Linux machine.
Try "print(pd.__version__)" to see which version you have.

Also, trying asking over at 
https://groups.google.com/forum/?fromgroups=#!forum/pydata which is more 
dedicated to pandas.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbee question about running a script

2013-01-06 Thread Miki Tebeka
On Sunday, January 6, 2013 8:03:43 AM UTC-8, marc.assin wrote:
> I wonder how I could specify a parameter on the command line from
> within the interpreter.
Guido wrote some advice a while back - 
http://www.artima.com/weblogs/viewpost.jsp?thread=4829

Import your module and call its main.

The other way is to execute in another process:
from subprocess import check_call
import sys
check_call([sys.executable, 'myscript.py', 'arg1', 'arg2'])
-- 
http://mail.python.org/mailman/listinfo/python-list



Re: Newbie problem with Python pandas

2013-01-06 Thread RueTheDay
On Sun, 06 Jan 2013 08:05:59 -0800, Miki Tebeka wrote:

> On Sunday, January 6, 2013 5:57:17 AM UTC-8, RueTheDay wrote:
>> I am getting the following error when running on Python 2.7 on Ubuntu
>> 12.04:
>> >>
>> >>
>> AttributeError: 'Series' object has no attribute 'str'
> I would *guess* that  you have an older version of pandas on your Linux
> machine.
> Try "print(pd.__version__)" to see which version you have.
> 
> Also, trying asking over at
> https://groups.google.com/forum/?fromgroups=#!forum/pydata which is more
> dedicated to pandas.

Thank you!  That was it.  I had 0.7 installed (the latest in the Ubuntu 
repository).  I downloaded and manually installed 0.10 and now it's 
working.  Coincidentally, this also fixed a problem I was having with 
running a matplotlib plot function against a pandas Data Frame (worked 
with some chart types but not others).

I'm starting to understand why people rely on easy_install and pip.  
Thanks again.
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem with Unicode char in Python 3.3.0

2013-01-06 Thread Franck Ditter
Hi !
I work on MacOS-X Lion and IDLE/Python 3.3.0
I can't get the treble key (U1D11E) !

>>> "\U1D11E"
SyntaxError: (unicode error) 'unicodeescape' codec can't 
decode bytes in position 0-6: end of string in escape sequence

How can I display musical keys ?

Thanks,

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


Re: Newbie problem with Python pandas

2013-01-06 Thread Roy Smith
In article <_dudnttyxduonxtnnz2dnuvz_ocdn...@giganews.com>,
 RueTheDay  wrote:

> On Sun, 06 Jan 2013 08:05:59 -0800, Miki Tebeka wrote:
> 
> > On Sunday, January 6, 2013 5:57:17 AM UTC-8, RueTheDay wrote:
> >> I am getting the following error when running on Python 2.7 on Ubuntu
> >> 12.04:
> >> >>
> >> >>
> >> AttributeError: 'Series' object has no attribute 'str'
> > I would *guess* that  you have an older version of pandas on your Linux
> > machine.
> > Try "print(pd.__version__)" to see which version you have.
> > 
> > Also, trying asking over at
> > https://groups.google.com/forum/?fromgroups=#!forum/pydata which is more
> > dedicated to pandas.
> 
> Thank you!  That was it.  I had 0.7 installed (the latest in the Ubuntu 
> repository).  I downloaded and manually installed 0.10 and now it's 
> working.  Coincidentally, this also fixed a problem I was having with 
> running a matplotlib plot function against a pandas Data Frame (worked 
> with some chart types but not others).
> 
> I'm starting to understand why people rely on easy_install and pip.  
> Thanks again.

Yeah, Ubuntu is a bit of a mess when it comes to pandas and the things 
it depends on.  Apt gets you numpy 1.4.1, which is really old.  Pandas 
won't even install on top of it.

I've got pandas (and numpy, and scipy, and matplotlib) running on a 
Ubuntu 12.04 box.  I installed everything with pip.  My problem at this 
point, however, is I want to replicate that setup in EMR (Amazon's 
Elastic Map-Reduce).  In theory, I could just run "pip install numpy" in 
my mrjob.conf bootstrap, but it's a really long install process, 
building a lot of stuff from source.  Not the kind of thing you want to 
put in a bootstrap for an ephemeral instance.

Does anybody know where I can find a debian package for numpy 1.6?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with Unicode char in Python 3.3.0

2013-01-06 Thread Peter Otten
Franck Ditter wrote:

> I work on MacOS-X Lion and IDLE/Python 3.3.0
> I can't get the treble key (U1D11E) !
> 
 "\U1D11E"
> SyntaxError: (unicode error) 'unicodeescape' codec can't
> decode bytes in position 0-6: end of string in escape sequence
> 
> How can I display musical keys ?

Try
>>> "\U0001D11E"
'𝄞'


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


Re: Newbie problem with Python pandas

2013-01-06 Thread RueTheDay
On Sun, 06 Jan 2013 11:45:34 -0500, Roy Smith wrote:

> In article <_dudnttyxduonxtnnz2dnuvz_ocdn...@giganews.com>,
>  RueTheDay  wrote:
> 
>> On Sun, 06 Jan 2013 08:05:59 -0800, Miki Tebeka wrote:
>> 
>> > On Sunday, January 6, 2013 5:57:17 AM UTC-8, RueTheDay wrote:
>> >> I am getting the following error when running on Python 2.7 on
>> >> Ubuntu 12.04:
>> >> >>
>> >> >>
>> >> AttributeError: 'Series' object has no attribute 'str'
>> > I would *guess* that  you have an older version of pandas on your
>> > Linux machine.
>> > Try "print(pd.__version__)" to see which version you have.
>> > 
>> > Also, trying asking over at
>> > https://groups.google.com/forum/?fromgroups=#!forum/pydata which is
>> > more dedicated to pandas.
>> 
>> Thank you!  That was it.  I had 0.7 installed (the latest in the Ubuntu
>> repository).  I downloaded and manually installed 0.10 and now it's
>> working.  Coincidentally, this also fixed a problem I was having with
>> running a matplotlib plot function against a pandas Data Frame (worked
>> with some chart types but not others).
>> 
>> I'm starting to understand why people rely on easy_install and pip.
>> Thanks again.
> 
> Yeah, Ubuntu is a bit of a mess when it comes to pandas and the things
> it depends on.  Apt gets you numpy 1.4.1, which is really old.  Pandas
> won't even install on top of it.
> 
> I've got pandas (and numpy, and scipy, and matplotlib) running on a
> Ubuntu 12.04 box.  I installed everything with pip.  My problem at this
> point, however, is I want to replicate that setup in EMR (Amazon's
> Elastic Map-Reduce).  In theory, I could just run "pip install numpy" in
> my mrjob.conf bootstrap, but it's a really long install process,
> building a lot of stuff from source.  Not the kind of thing you want to
> put in a bootstrap for an ephemeral instance.
> 
> Does anybody know where I can find a debian package for numpy 1.6?

Go here:

http://neuro.debian.net/index.html#how-to-use-this-repository

and add one their repositories to your sources.

Then you can do use apt-get to install ALL the latest packages on your 
Ubuntu box - numpy, scipy, pandas, matplotlib, statsmodels, etc.

I wish I found this a few days ago.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with Unicode char in Python 3.3.0

2013-01-06 Thread marduk


On Sun, Jan 6, 2013, at 11:43 AM, Franck Ditter wrote:
> Hi !
> I work on MacOS-X Lion and IDLE/Python 3.3.0
> I can't get the treble key (U1D11E) !
> 
> >>> "\U1D11E"
> SyntaxError: (unicode error) 'unicodeescape' codec can't 
> decode bytes in position 0-6: end of string in escape sequence
> 

You probably meant:

>>> '\U0001d11e'


For that synax you must use either '\u' or '\U' (i.e.
specify either 4 or 8 hex digits).

http://docs.python.org/2/howto/unicode#unicode-literals-in-python-source-code

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


Re: Need a specific sort of string modification. Can someone help?

2013-01-06 Thread Roy Smith
In article ,
 Roy Smith  wrote:

> It's rare to find applications these days that are truly CPU bound.  
> Once you've used some reasonable algorithm, i.e. not done anything in 
> O(n^2) that could have been done in O(n) or O(n log n), you will more 
> often run up against I/O speed, database speed, network latency, memory 
> exhaustion, or some such as the reason your code is too slow.

Well, I just found a counter-example :-)

I've been doing some log analysis.  It's been taking a grovelingly long 
time, so I decided to fire up the profiler and see what's taking so 
long.  I had a pretty good idea of where the ONLY TWO POSSIBLE hotspots 
might be (looking up IP addresses in the geolocation database, or 
producing some pretty pictures using matplotlib).  It was just a matter 
of figuring out which it was.

As with most attempts to out-guess the profiler, I was totally, 
absolutely, and embarrassingly wrong.

It turns out we were spending most of the time parsing timestamps!  
Since there's no convenient way (I don't consider strptime() to be 
convenient) to parse isoformat strings in the standard library, our 
habit has been to use the oh-so-simple parser from the third-party 
dateutil package.  Well, it turns out that's slow as all get-out 
(probably because it's trying to be smart about auto-recognizing 
formats).  For the test I ran (on a few percent of the real data), we 
spent 90 seconds in parse().

OK, so I dragged out the strptime() docs and built the stupid format 
string (%Y-%m-%dT%H:%M:%S+00:00).  That got us down to 25 seconds in 
strptime().

But, I could also see it was spending a significant amount in routines 
that looked like they were computing things like day of the week that we 
didn't need.  For what I was doing, we only really needed the hour and 
minute.  So I tried:

t_hour = int(date[11:13])
t_minute = int(date[14:16])

that got us down to 12 seconds overall (including the geolocation and 
pretty pictures).

I think it turns out we never do anything with the hour and minute other 
than print them back out, so just

   t_hour_minute = date[11:16]

would probably be good enough, but I think I'm going to stop where I am 
and declare victory :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie problem with Python pandas

2013-01-06 Thread Roy Smith
In article <_dudntfyxdvclhtnnz2dnuvz_ocdn...@giganews.com>,
 RueTheDay  wrote:

> On Sun, 06 Jan 2013 11:45:34 -0500, Roy Smith wrote:
> 
> > In article <_dudnttyxduonxtnnz2dnuvz_ocdn...@giganews.com>,
> >  RueTheDay  wrote:
> > 
> >> On Sun, 06 Jan 2013 08:05:59 -0800, Miki Tebeka wrote:
> >> 
> >> > On Sunday, January 6, 2013 5:57:17 AM UTC-8, RueTheDay wrote:
> >> >> I am getting the following error when running on Python 2.7 on
> >> >> Ubuntu 12.04:
> >> >> >>
> >> >> >>
> >> >> AttributeError: 'Series' object has no attribute 'str'
> >> > I would *guess* that  you have an older version of pandas on your
> >> > Linux machine.
> >> > Try "print(pd.__version__)" to see which version you have.
> >> > 
> >> > Also, trying asking over at
> >> > https://groups.google.com/forum/?fromgroups=#!forum/pydata which is
> >> > more dedicated to pandas.
> >> 
> >> Thank you!  That was it.  I had 0.7 installed (the latest in the Ubuntu
> >> repository).  I downloaded and manually installed 0.10 and now it's
> >> working.  Coincidentally, this also fixed a problem I was having with
> >> running a matplotlib plot function against a pandas Data Frame (worked
> >> with some chart types but not others).
> >> 
> >> I'm starting to understand why people rely on easy_install and pip.
> >> Thanks again.
> > 
> > Yeah, Ubuntu is a bit of a mess when it comes to pandas and the things
> > it depends on.  Apt gets you numpy 1.4.1, which is really old.  Pandas
> > won't even install on top of it.
> > 
> > I've got pandas (and numpy, and scipy, and matplotlib) running on a
> > Ubuntu 12.04 box.  I installed everything with pip.  My problem at this
> > point, however, is I want to replicate that setup in EMR (Amazon's
> > Elastic Map-Reduce).  In theory, I could just run "pip install numpy" in
> > my mrjob.conf bootstrap, but it's a really long install process,
> > building a lot of stuff from source.  Not the kind of thing you want to
> > put in a bootstrap for an ephemeral instance.
> > 
> > Does anybody know where I can find a debian package for numpy 1.6?
> 
> Go here:
> 
> http://neuro.debian.net/index.html#how-to-use-this-repository
> 
> and add one their repositories to your sources.
> 
> Then you can do use apt-get to install ALL the latest packages on your 
> Ubuntu box - numpy, scipy, pandas, matplotlib, statsmodels, etc.
> 
> I wish I found this a few days ago.

Cool, thanks!  Really glad you're a few days ahead of me :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


??????????? when was jesus christ born

2013-01-06 Thread BV BV
? when was jesus christ born


http://www.youtube.com/v/Qxjk3FGy71g?rel=0


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


Re: Good Python IDE

2013-01-06 Thread Monte Milanuk
Lots of good options out there... currently I'm liking spyder or eclipse 
a lot.


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


Specifying two log files with one configuration file

2013-01-06 Thread Peter Steele
I want to configure the Python logging module to manage two separate log files, 
allowing me to do something like this:

import logging
import logging.config
logging.config.fileConfig("mylogging.conf")
root = logging.getLogger()
test = logging.getLogger("test")

root.debug("This is a message targeted to the root log file")
test.debug("This is a message targeted to the test log file")

I have been unable to get this to work. My current conf file looks like this:

  [formatters]
  keys: simple

  [handlers]
  keys: root,test

  [loggers]
  keys: root,test

  [formatter_simple]
  format=%(asctime)s - %(levelname)s - %(message)s

  [handler_root]
  class: handlers.RotatingFileHandler
  args: ('/var/log/root.log', 'a', 1024000, 14)
  formatter: simple

  [handler_test]
  class: handlers.RotatingFileHandler
  args: ('/var/log/test.log', 'a', 1024000, 14)
  formatter: simple

  [logger_root]
  level: DEBUG
  handlers: root
  qualname:

  [logger_test]
  level: DEBUG
  handlers: test
  qualname:

With this setup, all of my log messages go to test.log. root.log is created, 
but nothing gets logged to it. What do I need in my logging conf file to have 
two separate log file destinations?
-- 
http://mail.python.org/mailman/listinfo/python-list


SOLUTIONS MANUAL TO Orbital Mechanics for Engineering Students 2nd ED by Curtis

2013-01-06 Thread kalvinmanual
I have solutions manuals to all problems and exercises in these textbooks. To 
get one in an electronic format contact me at: kalvinmanual(at)gmail(dot)com 
and let me know its title, author and edition. Please this service is NOT free.

SOLUTIONS MANUAL TO Probability & Statistics for Engineers & Scientists (8th 
Ed., Walpole,Myers, Ye)
SOLUTIONS MANUAL TO Probability and Statistical Inference ( 8th Ed, Hogg & 
Tanis )
SOLUTIONS MANUAL TO Probability and Statistical Inference (7th Ed., Hogg & 
Tanis)
SOLUTIONS MANUAL TO Probability and Statistics for Engineering and the 
Sciences, 6th Ed., by Jay L. Devore
SOLUTIONS MANUAL TO Probability and Statistics for Engineers 7 Ed Johnson 
Miller Freund 
SOLUTIONS MANUAL TO Probability and Statistics for Engineers 8th Ed by Miller, 
Freund
SOLUTIONS MANUAL TO Probability and Statistics for Engineers and Scientists 3rd 
Ed by Hayter
SOLUTIONS MANUAL TO Probability and Statistics in Engineering (4th Ed., Hines, 
Montgomery, Goldsman & Borror)
SOLUTIONS MANUAL TO Probability and Stochastic Processes 2E, by Roy D. Yates , 
David J. Goodman
SOLUTIONS MANUAL TO Probability Concepts in Engineering Emphasis on 
Applications to Civil and Environmental Engineering 2nd ED by Alfredo Ang and 
Wilson Tang
SOLUTIONS MANUAL TO Probability For Risk Management, Hassett, Stewart
SOLUTIONS MANUAL TO Probability Random Variables, and Stochastic Processes, 4th 
Ed., by Papoulis, Pillai
SOLUTIONS MANUAL TO Probability, Random Variables and Stochastic Processes, 3rd 
Edition Athanasios Papoulis
SOLUTIONS MANUAL TO Probability, Random Variables, and Random Signal Principles 
4th Ed by Peyton, Peebles
SOLUTIONS MANUAL TO Probability, Statistics, and Random Processes for 
Electrical Engineers 3rd E by A. Leon-Garcia
SOLUTIONS MANUAL TO Probability, Statistics, and Random Processes for 
Engineers, Richard H. Williams
SOLUTIONS MANUAL TO Problems and Solutions on Electromagnetism by Lim Yung-Kuo
SOLUTIONS MANUAL TO Problems in general physics by I. E Irodov
SOLUTIONS MANUAL TO Problems in General Physics vol.I & vol.II Irodov
SOLUTIONS MANUAL TO Process Control Instrumentation Technology, 8 ed by Curtis 
D. Johnson
SOLUTIONS MANUAL TO Process Dynamics and Control 2nd ED by Seborg, Edgar and 
Mellichamp
SOLUTIONS MANUAL TO PROCESS SYSTEMS ANALYSIS AND by COUGHANOWR
SOLUTIONS MANUAL TO Programmable Logic Controllers (James A. Rehg, Glenn J. 
Sartori) 
SOLUTIONS MANUAL TO Psychology and Life 16th ed by Gerrig and Zimbardo
SOLUTIONS MANUAL TO Psychology and Life by Gerrig & Zimbardo ,16th edition
SOLUTIONS MANUAL TO Quantitative Methods for Management by PINNEY, McWILLIAMS, 
ORMSBY, ATCHISON
SOLUTIONS MANUAL TO Quantum Electronics for Atomic Physics by Warren Nagourney
SOLUTIONS MANUAL TO Quantum Field Theory Mark Srednicki
SOLUTIONS MANUAL TO Quantum Mechanics - B. Brinne
SOLUTIONS MANUAL TO Quantum Mechanics: An Accessible Introduction (Robert 
Scherrer)
SOLUTIONS MANUAL TO Quantum Physics of Atoms, Molecules, Solids, Nuclei and 
Particles 2 nd by  Eisberg
SOLUTIONS MANUAL TO Quantum Physics, 3rd Edition, by Stephen Gasiorowicz
SOLUTIONS MANUAL TO Quantum theory of light 3 Ed by Rodney Loudon
SOLUTIONS MANUAL TO Queueing Systems (Volume 1 - Theory) by  Leonard Kleinrock, 
Richard Gail
SOLUTIONS MANUAL TO Real Analysis 1st Edition by H. L. Royden
SOLUTIONS MANUAL TO Real and Complex Analysis by Nguyen, Burckel
SOLUTIONS MANUAL TO Recursive Methods in Economic Dynamics, (2002) by Irigoyen, 
Rossi- Hansberg, Wright 
SOLUTIONS MANUAL TO Reinforced Concrete: Mechanics and Design (5th Ed., James 
G. MacGregor & James K. Wight)
SOLUTIONS MANUAL TO RF Circuit Design: Theory & Applications, by Bretchko, 
Ludwig
SOLUTIONS MANUAL TO Satellite Communications 2nd Ed By Timothy Pratt, Charles 
W. Bostian
SOLUTIONS MANUAL TO Scientific Computing with Case Studies by Dianne P. O'Leary
SOLUTIONS MANUAL TO Semiconductor Device Fundamentals by Pierret
SOLUTIONS MANUAL TO SEMICONDUCTOR DEVICES Physics and Technology 2nd Ed by SZE
SOLUTIONS MANUAL TO Semiconductor Physics and Applications by Balkanski, Wallis
SOLUTIONS MANUAL TO Semiconductor Physics and Devices (3rd Ed., Donald A. 
Neamen)
SOLUTIONS MANUAL TO Semiconductor Physics and Devices 4th E by Donald A. Neamen
SOLUTIONS MANUAL TO Separation Process Principles 2nd ED by Seader, Henley
SOLUTIONS MANUAL TO Separation Process Principles by Seader & Henley
SOLUTIONS MANUAL TO SERWAY AND VUILLE’S COLLEGE PHYSICS NINTH EDITION 
SOLUTIONS MANUAL TO Shigley's Mechanical Engineering Design (8th Ed., Budynas)
SOLUTIONS MANUAL TO Signal Processing and Linear Systems by Lathi
SOLUTIONS MANUAL TO Signal Processing First by Mclellan, Schafer & Yoder
SOLUTIONS MANUAL TO Signals and Systems 2e by Haykin & B Van Veen
SOLUTIONS MANUAL TO Signals and Systems 2nd Edition Oppenheim, Willsky and Nawab
SOLUTIONS MANUAL TO Signals and Systems Analysis of Signals Through Linear 
Systems by M.J. Roberts, M.J. Roberts
SOLUTIONS MANUAL TO Signals and Systems, 2nd Edition, Oppenheim,

Re: Ubuntu Python -dbg packages

2013-01-06 Thread Terry Reedy

On 1/6/2013 8:42 AM, Lee Harr wrote:


I am using:
Ubuntu 12.10
Python 3.2.3


import has been considerably redone, and hopefully upgraded, in 3.3.


Qt 4.8.2
PyQt 4.9.3

I also have the ubuntu -dbg packages:
python3-dbg
python3-pyqt4-dbg



I don't understand why python3-dbg cannot import the PyQt4 modules...

$ python3
Python 3.2.3 (default, Oct 19 2012, 19:53:57)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import sys
sys.executable

'/usr/bin/python3'

import PyQt4


Is PyQtr.__file__ the same here, as below?


import PyQt4.QtCore




$ python3-dbg
Python 3.2.3 (default, Oct 19 2012, 19:58:54)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import sys

[60298 refs]

sys.executable

'/usr/bin/python3-dbg'
[60300 refs]

import PyQt4

[60323 refs]

PyQt4.__file__

'/usr/lib/python3/dist-packages/PyQt4/__init__.py'
[60323 refs]

import PyQt4.QtCore

Traceback (most recent call last):
   File "", line 1, in 
ImportError: No module named QtCore
[150996 refs]


--
Terry Jan Reedy

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


Numpy outlier removal

2013-01-06 Thread Joseph L. Casale
I have a dataset that consists of a dict with text descriptions and values that 
are integers. If
required, I collect the values into a list and create a numpy array running it 
through a simple
routine: data[abs(data - mean(data)) < m * std(data)] where m is the number of 
std deviations
to include.


The problem is I loos track of which were removed so the original display of 
the dataset is
misleading when the processed average is returned as it includes the removed 
key/values.


Ayone know how I can maintain the relationship and when I exclude a value, 
remove it from
the dict?

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


Re: Need a specific sort of string modification. Can someone help?

2013-01-06 Thread Mitya Sirenef

On 01/06/2013 01:32 AM, Mitya Sirenef wrote:

On 01/05/2013 03:35 AM, Sia wrote:

I have strings such as:

>
> tA.-2AG.-2AG,-2ag
> or
> .+3ACG.+5CAACG.+3ACG.+3ACG
>
> The plus and minus signs are always followed by a number (say, i). I 
want python to find each single plus or minus, remove the sign, the 
number after it and remove i characters after that. So the two strings 
above become:

>
> tA..,
> and
> ...
>
> How can I do that?
> Thanks.


I think it's a bit cleaner and nicer to do something similar to
itertools.takewhile but takewhile 'eats' a single next value.
I was actually doing some stuff that also needed this. I wonder if
there's a more elegant, robust way to do this?

Here's what I got for now:


class BIterator(object):
"""Iterator with 'buffered' takewhile."""

def __init__(self, seq):
self.seq= iter(seq)
self.buffer = []
self.end_marker = object()
self.last   = None

def consume(self, n):
for _ in range(n): self.next()

def next(self):
val = self.buffer.pop() if self.buffer else next(self.seq, 
self.end_marker)

self.last = val
return val

def takewhile(self, test):
lst = []
while True:
val = self.next()
if val is self.end_marker:
return lst
elif test(val):
lst.append(val)
else:
self.buffer.append(val)
return lst

def joined_takewhile(self, test):
return ''.join(self.takewhile(test))

def done(self):
return bool(self.last is self.end_marker)


s = ".+3ACG.+5CAACG.+3ACG.+3ACG"
not_plusminus = lambda x: x not in "+-"
isdigit   = lambda x: x.isdigit()

def process(s):
lst = []
s   = BIterator(s)

while True:
lst.extend(s.takewhile(not_plusminus))
if s.done(): break
s.next()
n = int(s.joined_takewhile(isdigit))
s.consume(n)

return ''.join(lst)


print(process(s))


Obviously it assumes the input is well-formed, but the logic would be
very easy to change to, for example, check for s.done() after each step.

 - mitya





I've added some refinements:



class BIterator(object):
"""Iterator with 'buffered' takewhile and takeuntil."""

def __init__(self, seq):
self.seq= iter(seq)
self.buffer = []
self.end_marker = object()
self.last   = None

def __bool__(self):
return self.last is not self.end_marker

def __next__(self):
val = self.buffer.pop() if self.buffer else next(self.seq, 
self.end_marker)

self.last = val
return val

def consume(self, n):
for _ in range(n): next(self)

def takewhile(self, test):
lst = []
while True:
val = next(self)
if val is self.end_marker:
return lst
elif test(val):
lst.append(val)
else:
self.buffer.append(val)
return lst

def takeuntil(self, test):
negtest = lambda x: not test(x)
return self.takewhile(negtest)

def joined_takewhile(self, test):
return ''.join(self.takewhile(test))

def joined_takeuntil(self, test):
return ''.join(self.takeuntil(test))


def process(s):
s = BIterator(s)
lst   = []
plusminus = lambda x: x in "+-"
isdigit   = lambda x: x.isdigit()

while s:
lst.extend(s.takeuntil(plusminus))
next(s)
n = s.joined_takewhile(isdigit) or 0
s.consume(int(n))

return ''.join(lst)


s = ".+3ACG.+5CAACG.+3ACG.+3ACG"
print(process(s))




--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

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


Re: Ubuntu Python -dbg packages

2013-01-06 Thread Lee Harr

> On 1/6/2013 8:42 AM, Lee Harr wrote:
>>
>> I am using:
>> Ubuntu 12.10
>> Python 3.2.3
>
> import has been considerably redone, and hopefully upgraded, in 3.3.


Ok, so now I tried python3.3-dbg but I don't think the pyqt
modules are compiled for 3.3 and that may be preventing
the import there.

Those extension modules would need to be compiled for
an exactly matching python interpreter, right?



>> Qt 4.8.2
>> PyQt 4.9.3
>>
>> I also have the ubuntu -dbg packages:
>> python3-dbg
>> python3-pyqt4-dbg
>>
>>
>>
>> I don't understand why python3-dbg cannot import the PyQt4 modules...

> Is PyQtr.__file__ the same here, as below?

Yes. It's the same.

Sorry, that's what I meant to show there.

$ python3
Python 3.2.3 (default, Oct 19 2012, 19:53:57) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import PyQt4
>>> PyQt4.__file__
'/usr/lib/python3/dist-packages/PyQt4/__init__.py'
>>>



>> $ python3-dbg
>> Python 3.2.3 (default, Oct 19 2012, 19:58:54)
>> [GCC 4.7.2] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
> import sys
>> [60298 refs]
> sys.executable
>> '/usr/bin/python3-dbg'
>> [60300 refs]
> import PyQt4
>> [60323 refs]
> PyQt4.__file__
>> '/usr/lib/python3/dist-packages/PyQt4/__init__.py'
>> [60323 refs]
> import PyQt4.QtCore
>> Traceback (most recent call last):
>>    File "", line 1, in 
>> ImportError: No module named QtCore
>> [150996 refs]


So, python3-dbg _should_ be able to import this?

Any ideas about the python3-pyqt4-dbg modules mentioned originally?

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


How do you call a function several times in this context??

2013-01-06 Thread kofi
Using python 3.1, I have written a function called "isEvenDigit"

Below is the code for the "isEvenDigit" function:

def isEvenDigit():
ste=input("Please input a single character string: ")
li=["0","2","4", "6", "8"]
if ste in li:
print("True")
else:
print("False")

I am now trying to write a function that takes a string as an argument and 
makes several calls to the isEvenDigit function in order to calculate and 
return the number of even digits in the string.How do i do this please? This is 
what i have done so far.

def isEvenDigit2():
number = input("Enter a digit: ")
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do you call a function several times in this context??

2013-01-06 Thread Benjamin Kaplan
On Jan 6, 2013 12:33 PM, "kofi"  wrote:
>
> Using python 3.1, I have written a function called "isEvenDigit"
>
> Below is the code for the "isEvenDigit" function:
>
> def isEvenDigit():
> ste=input("Please input a single character string: ")
> li=["0","2","4", "6", "8"]
> if ste in li:
> print("True")
> else:
> print("False")
>
> I am now trying to write a function that takes a string as an argument
and makes several calls to the isEvenDigit function in order to calculate
and return the number of even digits in the string.How do i do this please?
This is what i have done so far.
>
> def isEvenDigit2():
> number = input("Enter a digit: ")

Use a loop and call the function in the body of the loop. In this case, you
would use a for loop iterating over number. If you don't know how to use a
for loop, I recommend you do the tutorial at
http://docs.python.org/3.3/tutorial/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do you call a function several times in this context??

2013-01-06 Thread Alister
On Sun, 06 Jan 2013 12:26:40 -0800, kofi wrote:

> Using python 3.1, I have written a function called "isEvenDigit"
> 
> Below is the code for the "isEvenDigit" function:
> 
> def isEvenDigit():
> ste=input("Please input a single character string: ")
> li=["0","2","4", "6", "8"]
> if ste in li:
> print("True")
> else:
> print("False")
> 
> I am now trying to write a function that takes a string as an argument
> and makes several calls to the isEvenDigit function in order to
> calculate and return the number of even digits in the string.How do i do
> this please? This is what i have done so far.
> 
> def isEvenDigit2():
> number = input("Enter a digit: ")
you need to investigate passing parameters to and from function

as you are obviously a beginner I don't want to give you the answer to 
your task but hopefully steer you in the right direction.

examine the code below & see if you can understand how it is working & 
how to apply it to your current project

def double(value):
result
return result

number=input('type a number')
print (double(int(number)))

this program is for explanation only and a function this simple should 
never be used in a real program, it is functionally equivalent to

number=input('type a number')
print (int(number)*2)

-- 
Alex Haley was adopted!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do you call a function several times in this context??

2013-01-06 Thread Jason Friedman
> def double(value):
> result
> return result
>
> number=input('type a number')
> print (double(int(number)))
>

I think what was meant:

def double(value):
result = 2 * value
return result
-- 
http://mail.python.org/mailman/listinfo/python-list


psycopg2 cursor.execute CREATE TABLE issue

2013-01-06 Thread andydtaylor
Hi all,

I'm trying to create a process which will create a new table and populate it. 

But something is preventing this from working, and I don't know enough to 
figure it out, despite having spent most of today reading up. The code executes 
with no error, yet no table is created or populated.

Can anyone offer me some advice? code below. 

Thanks,

Andy

#!/usr/bin/python
import psycopg2
import sys

def main():
   db = psycopg2.connect(
  host = 'localhost',
  database = 'gisdb',
  user = 'postgres',
  password = 'L1ncoln0ut@'
   )
   cursor = db.cursor()
   cursor.execute("CREATE TABLE test (id serial PRIMARY KEY, num integer, data 
varchar);")
   cursor.execute("INSERT INTO test (num, data) VALUES (%s, %s)",(100, 
"abc'def"))

if __name__ == "__main__":
main()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: psycopg2 cursor.execute CREATE TABLE issue

2013-01-06 Thread Mitya Sirenef

On Sun 06 Jan 2013 04:38:29 PM EST, andydtay...@gmail.com wrote:

Hi all,

I'm trying to create a process which will create a new table and populate it.

But something is preventing this from working, and I don't know enough to 
figure it out, despite having spent most of today reading up. The code executes 
with no error, yet no table is created or populated.

Can anyone offer me some advice? code below.

Thanks,

Andy

#!/usr/bin/python
import psycopg2
import sys

def main():
db = psycopg2.connect(
   host = 'localhost',
   database = 'gisdb',
   user = 'postgres',
   password = 'L1ncoln0ut@'
)
cursor = db.cursor()
cursor.execute("CREATE TABLE test (id serial PRIMARY KEY, num integer, data 
varchar);")
cursor.execute("INSERT INTO test (num, data) VALUES (%s, %s)",(100, 
"abc'def"))

if __name__ == "__main__":
main()



To commit a transaction, you need to do a db.commit() call.

-m



--
Lark's Tongue Guide to Python: http://lightbird.net/larks/
--
http://mail.python.org/mailman/listinfo/python-list


Re: psycopg2 cursor.execute CREATE TABLE issue

2013-01-06 Thread Chris Angelico
On Mon, Jan 7, 2013 at 8:38 AM,   wrote:
> But something is preventing this from working, and I don't know enough to 
> figure it out, despite having spent most of today reading up. The code 
> executes with no error, yet no table is created or populated.

Standard databasing requirement: You need to commit your work.

http://initd.org/psycopg/docs/connection.html#connection.commit

Otherwise, the transaction gets rolled back, and nobody sees your changes.

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


Re: psycopg2 cursor.execute CREATE TABLE issue

2013-01-06 Thread andydtaylor
Wow it's as simple as that! I'm afraid my database experience is in Microsoft 
Access in Windows and not at the command line, so that wasn't intuitive for me.

Thanks again,

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


Re: How do you call a function several times in this context??

2013-01-06 Thread Joel Goldstick
On Sun, Jan 6, 2013 at 4:33 PM, Jason Friedman  wrote:

> > def double(value):
> > result
> > return result
> >
> > number=input('type a number')
> > print (double(int(number)))
> >
>
> I think what was meant:
>
> def double(value):
> result = 2 * value
> return result
> --
> http://mail.python.org/mailman/listinfo/python-list
>

#get the string of numbers outside your function:

is_even
number = input("type an integer')

#Here is some code to loop through each digit

for n in number:
is_even_digit(n)  # this function should test the number and print what
you want for odd and even

#This will pass each digit to your function.  I renamed your function to
reflect better python naming conventions



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


Re: psycopg2 cursor.execute CREATE TABLE issue

2013-01-06 Thread Mitya Sirenef

On Sun 06 Jan 2013 04:53:32 PM EST, andydtay...@gmail.com wrote:

Wow it's as simple as that! I'm afraid my database experience is in Microsoft 
Access in Windows and not at the command line, so that wasn't intuitive for me.

Thanks again,

Andy



IIRC I made the same mistake when I was using psycopg for the first 
time.

I think wrapper libraries like sqlalchemy usually have myrecord.save()
method which is more intuitive.

-m


--
Lark's Tongue Guide to Python: http://lightbird.net/larks/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Good Python IDE

2013-01-06 Thread Tim Johnson
* Sourabh Mhaisekar  [130106 07:11]:
> Hello All, 
> I am recently started couple of projects in Python, one in Python GTK and one 
> in Python Qt. I want a good IDE (For Windows ) for Python which gives support 
> for Python as well as PyGtk and PyQt. 
> 
> Features I am looking for 
> * Support for Core Python Auto-completion.
> * Support for PyGtk and PyQt
> * Support for either Bazaar (preferred) or CVS
  I haven't developed on windows in over 10 years, but as I recall,
  pythonwin worked well for me at the time. I don't recall whether
  the 2nd and 3rd features you refer to were available, but the
  first was. It is easy enough to try.

  Now I use vim for all of my work. I pretty-much hand-rolled my own
  IDE, which is typical of vimmers.
-- 
Tim 
tim at tee jay forty nine dot com or akwebsoft dot com
http://www.akwebsoft.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: psycopg2 cursor.execute CREATE TABLE issue

2013-01-06 Thread Chris Angelico
On Mon, Jan 7, 2013 at 9:14 AM, Mitya Sirenef  wrote:
> On Sun 06 Jan 2013 04:53:32 PM EST, andydtay...@gmail.com wrote:
>>
>> Wow it's as simple as that! I'm afraid my database experience is in
>> Microsoft Access in Windows and not at the command line, so that wasn't
>> intuitive for me.
>>
> IIRC I made the same mistake when I was using psycopg for the first time.
> I think wrapper libraries like sqlalchemy usually have myrecord.save()
> method which is more intuitive.

I recommend getting used to thinking in terms of transactions and
commits. Instead of saving a record, commit a unit of work, which
might involve several changes all at once. A good database (like
PostgreSQL) will guarantee you that either the whole transaction has
happened, or none of it has. And normally, once your commit call has
returned (assuming it doesn't raise an error), you're guaranteed that
the transaction has been completely written to durable storage. Of
course, that depends on *having* durable storage, and many SSDs lie
about what's been written, but that's outside the scope of this post!

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


Re: Good Python IDE

2013-01-06 Thread Almar Klein
IEP has support for integrating the event loops of both GTK and Qt:
https://code.google.com/p/iep/  No version control support though.

- Almar


On 6 January 2013 19:06, Monte Milanuk  wrote:

> Lots of good options out there... currently I'm liking spyder or eclipse a
> lot.
>
> --
> http://mail.python.org/**mailman/listinfo/python-list
>



-- 
Almar Klein, PhD
Science Applied
phone: +31 6 19268652
e-mail: a.kl...@science-applied.nl
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Numpy outlier removal

2013-01-06 Thread Hans Mulder
On 6/01/13 20:44:08, Joseph L. Casale wrote:
> I have a dataset that consists of a dict with text descriptions and values 
> that are integers. If
> required, I collect the values into a list and create a numpy array running 
> it through a simple
> routine: data[abs(data - mean(data)) < m * std(data)] where m is the number 
> of std deviations
> to include.
> 
> 
> The problem is I loos track of which were removed so the original display of 
> the dataset is
> misleading when the processed average is returned as it includes the removed 
> key/values.
> 
> 
> Ayone know how I can maintain the relationship and when I exclude a value, 
> remove it from
> the dict?

Assuming your data and the dictionary are keyed by a common set of keys:

for key in descriptions:
if abs(data[key] - mean(data)) >= m * std(data):
del data[key]
del descriptions[key]


Hope this helps,

-- HansM

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


Re: How do you call a function several times in this context??

2013-01-06 Thread Alister
On Sun, 06 Jan 2013 14:33:26 -0700, Jason Friedman wrote:

>> def double(value):
>> result return result
>>
>> number=input('type a number')
>> print (double(int(number)))
>>
>>
> I think what was meant:
> 
> def double(value):
> result = 2 * value return result

yes indeed
thanks for correcting my typo





-- 
Quigley's Law:
Whoever has any authority over you, no matter how small, will
atttempt to use it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: psycopg2 cursor.execute CREATE TABLE issue

2013-01-06 Thread Walter Hurry
On Sun, 06 Jan 2013 16:44:47 -0500, Mitya Sirenef wrote:

> On Sun 06 Jan 2013 04:38:29 PM EST, andydtay...@gmail.com wrote:
>> Hi all,
>>
>> I'm trying to create a process which will create a new table and
>> populate it.
>>
>> But something is preventing this from working, and I don't know enough
>> to figure it out, despite having spent most of today reading up. The
>> code executes with no error, yet no table is created or populated.
>>
>> Can anyone offer me some advice? code below.
>>
>> Thanks,
>>
>> Andy
>>
>> #!/usr/bin/python import psycopg2 import sys
>>
>> def main():
>> db = psycopg2.connect(
>>host = 'localhost', database = 'gisdb', user = 'postgres',
>>password = 'L1ncoln0ut@'
>> )
>> cursor = db.cursor()
>> cursor.execute("CREATE TABLE test (id serial PRIMARY KEY, num
>> integer, data varchar);")
>> cursor.execute("INSERT INTO test (num, data) VALUES (%s, %s)",(100,
>> "abc'def"))
>>
>> if __name__ == "__main__":
>>  main()
> 
> 
> To commit a transaction, you need to do a db.commit() call.

Or set autocommit = True on the database connection object
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Numpy outlier removal

2013-01-06 Thread Joseph L. Casale
>Assuming your data and the dictionary are keyed by a common set of keys: 

>
>for key in descriptions:
>    if abs(data[key] - mean(data)) >= m * std(data):
>        del data[key]
>        del descriptions[key]


Heh, yeah sometimes the obvious is too simple to see. I used a dict comp to 
rebuild
the results with the comparison.


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


Re: Numpy outlier removal

2013-01-06 Thread MRAB

On 2013-01-06 22:33, Hans Mulder wrote:

On 6/01/13 20:44:08, Joseph L. Casale wrote:

I have a dataset that consists of a dict with text descriptions and values that 
are integers. If
required, I collect the values into a list and create a numpy array running it 
through a simple
routine: data[abs(data - mean(data)) < m * std(data)] where m is the number of 
std deviations
to include.


The problem is I loos track of which were removed so the original display of 
the dataset is
misleading when the processed average is returned as it includes the removed 
key/values.


Ayone know how I can maintain the relationship and when I exclude a value, 
remove it from
the dict?


Assuming your data and the dictionary are keyed by a common set of keys:

for key in descriptions:
 if abs(data[key] - mean(data)) >= m * std(data):
 del data[key]
 del descriptions[key]


It's generally a bad idea to modify a collection over which you're
iterating. It's better to, say, make a list of what you're going to
delete and then iterate over that list to make the deletions:

deletions = []

for key in in descriptions:
if abs(data[key] - mean(data)) >= m * std(data):
deletions.append(key)

for key in deletions:
del data[key]
del descriptions[key]

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


Re: Over 30 types of variables available in python ?

2013-01-06 Thread Chris Angelico
On Mon, Jan 7, 2013 at 10:12 AM, chaouche yacine
 wrote:
>
> booleans
> ints, floats, longs, complexes
> strings, unicode strings
> lists, tuples, dictionaries, dictionary views, sets, frozensets, buffers,
> bytearrays, slices
> functions, methods, code objects,modules,classes, instances, types, nulls
> (there is exactly one object of type Null which is None), tracebacks, frames
> generators, iterators, xranges,
> files,
> memoryviews,
> context managers,
>
> These are all listed in this page
> http://docs.python.org/2/library/stdtypes.html as built-in types. Am I
> getting anything wrong here ? I'm a bit confused about it. I have never seen
> so many types in the few programming languages I saw.

Not quite. Python has one type of variable: the name binding. Those
are different types of objects.

Since you can subclass object to make your own class, there's an
infinite number of types available. But the ones you'll be using in
most programs are:
* boolean, int, float (and long, in Python 2, but in Python 3 that's
the same as int)
* Unicode strings
* In Python 2, bytes strings
* lists, tuples, dicts, maybe sets
* functions
* files

The rest, you're unlikely to worry much about. The program will use
them under the covers, but you don't need to concern yourself with the
details. The only other thing you'll need to look at is the generic
handling of object() and, by virtue of subclassing, every other
object.

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


Re: Need a specific sort of string modification. Can someone help?

2013-01-06 Thread Steven D'Aprano
On Sun, 06 Jan 2013 12:28:55 -0500, Roy Smith wrote:

> I've been doing some log analysis.  It's been taking a grovelingly long
> time, so I decided to fire up the profiler and see what's taking so
> long.  I had a pretty good idea of where the ONLY TWO POSSIBLE hotspots
> might be (looking up IP addresses in the geolocation database, or
> producing some pretty pictures using matplotlib).  It was just a matter
> of figuring out which it was.
> 
> As with most attempts to out-guess the profiler, I was totally,
> absolutely, and embarrassingly wrong.

+1 QOTW

Thank you for sharing this with us. 


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


Re: Over 30 types of variables available in python ?

2013-01-06 Thread Dave Angel
On 01/06/2013 06:12 PM, chaouche yacine wrote:
> booleans
> ints, floats, longs, complexes
> strings, unicode strings
> lists, tuples, dictionaries, dictionary views, sets, frozensets, buffers, 
> bytearrays, slices
> functions, methods, code objects,modules,classes, instances, types, nulls 
> (there is exactly one object of type Null which is None), tracebacks, frames
> generators, iterators, xranges,
> files,
>
> memoryviews,
> context managers,
>
> These are all listed in this page 
> http://docs.python.org/2/library/stdtypes.html as built-in types. Am I 
> getting anything wrong here ? I'm a bit confused about it. I have never seen 
> so many types in the few programming languages I saw.
>

First, you're describing Python 2.x ;3.x is different in a few
ways.  For one, int and long are combined into a single type.

Variables don't have types.  Only objects have types.  A name can be
bound to any object, regardless of its type, or to what it might have
been previously bound.

Otherwise, you're right.  Python is a rich language, with "batteries
included."  There's a lot in the built-in space, but if you include the
stdlib, it's really rich.  And if you include the fact that objects you
define yourself are first-class, there are very few limits.



-- 

DaveA

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


Re: Good Python IDE

2013-01-06 Thread Tetsuya

On 01/06/2013 11:13 PM, Tim Johnson wrote:

   Now I use vim for all of my work. I pretty-much hand-rolled my own
   IDE, which is typical of vimmers.


I did like you, too.
I use vim for everything: coding in python, django, js, html, C/C++, 
bash, even email (inside mutt, of course).
Start with an empty ~/.vimrc, and then build up the configuration day by 
day, adding one single plugin at a time, driven by your daily needs, 
it's the better thing to do IMHO.
Thus vim becomes a full fledged IDE for everything, and it does it 
*your* way, not *its* way.


BTW, vim is available also under Windows.
--
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.realpath(path) bug on win7 ?

2013-01-06 Thread Victor Stinner
It looks like the following issue:
http://bugs.python.org/issue14094

Victor
Le 6 janv. 2013 07:59, "iMath" <2281570...@qq.com> a écrit :

> os.path.realpath(path)  bug on win7 ?
>
> Temp.link is a Symbolic link
> Its target location is C:\test\test1
> But
> >>> os.path.realpath(r'C:\Users\SAMSUNG\Temp.link\test2')
> 'C:\\Users\\SAMSUNG\\Temp.link\\test2'
>
> I thought the return value should be ' C:\\test\\test1\\test2'
>
> Is it a bug ? anyone can clear it to me ?
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Yet another attempt at a safe eval() call

2013-01-06 Thread Oscar Benjamin
On 6 January 2013 15:12, Grant Edwards  wrote:
> On 2013-01-05, Oscar Benjamin  wrote:
>> On 4 January 2013 15:53, Grant Edwards  wrote:
>>> On 2013-01-04, Steven D'Aprano  wrote:
 On Thu, 03 Jan 2013 23:25:51 +, Grant Edwards wrote:

 * But frankly, you should avoid eval, and write your own mini-integer
   arithmetic evaluator which avoids even the most remote possibility
   of exploit.
>>>
>>> That's obviously the "right" thing to do.  I suppose I should figure
>>> out how to use the ast module.
>>
>> Someone has already created a module that does this called numexpr. Is
>> there some reason why you don't want to use that?
>
> 1) I didn't know about it, and my Googling didn't find it.
>
> 2) It's not part of the standard library, and my program needs to be
>distributed as a single source file.

That's an unfortunate restriction. It also won't be possible to reuse
the code from numexpr (for technical rather than legal reasons).
Perhaps asteval will be more helpful in that sense.

Otherwise presumably the shunting-yard algorithm comes out a little
nicer in Python than in C (it would be useful if something like this
were available on PyPI as a pure Python module):
http://en.wikipedia.org/wiki/Shunting_yard_algorithm#C_example


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


INSTRUCTOR SOLUTIONS MANUAL :: Advanced Engineering Thermodynamics, 3rd Edition by Adrian Bejan

2013-01-06 Thread kalvinmanual
I have solutions manuals to all problems and exercises in these textbooks. To 
get one in an electronic format contact me at: kalvinmanual(at)gmail(dot)com 
and let me know its title, author and edition. Please this service is NOT free.

INSTRUCTOR SOLUTIONS MANUAL :: Field and Wave Electromagnetics 2nd Ed by David 
K. Cheng
INSTRUCTOR SOLUTIONS MANUAL :: Financial Accounting 6th E with Annual Report by 
Libby, Short
INSTRUCTOR SOLUTIONS MANUAL :: Financial Accounting 6th Ed by Harrison
INSTRUCTOR SOLUTIONS MANUAL :: Financial Accounting An Integrated Approach, 6th 
Ed by Gibbins 
INSTRUCTOR SOLUTIONS MANUAL :: Financial Management- Principles and 
Applications, 10th Ed by Keown, Scott
INSTRUCTOR SOLUTIONS MANUAL :: Financial Management- Theory and Practice 12 th 
ED by Brigham, Ehrhardt
INSTRUCTOR SOLUTIONS MANUAL :: Financial Reporting and Analysis Using Financial 
Accounting Information 10th Ed by Gibson
INSTRUCTOR SOLUTIONS MANUAL :: Financial Reporting and Analysis, 3E by Revsine, 
Collins, Johnson
INSTRUCTOR SOLUTIONS MANUAL :: Finite Element Techniques in Structural 
Mechanics Ross
INSTRUCTOR SOLUTIONS MANUAL :: First Course in Abstract Algebra, 3rd Ed by 
Joseph J. Rotman
INSTRUCTOR SOLUTIONS MANUAL :: First Course in Probability (7th Ed., Sheldon 
Ross)
INSTRUCTOR SOLUTIONS MANUAL :: Fluid Mechanics (5th Ed., White)
INSTRUCTOR SOLUTIONS MANUAL :: Fluid Mechanics 4th Ed by Cohen, Kundu
INSTRUCTOR SOLUTIONS MANUAL :: Fluid Mechanics 4th Edition by Frank M. White
INSTRUCTOR SOLUTIONS MANUAL :: Fluid Mechanics and Thermodynamics of 
Turbomachinery (5th Ed., S.L. Dixon)
INSTRUCTOR SOLUTIONS MANUAL :: Fluid Mechanics by CENGEL
INSTRUCTOR SOLUTIONS MANUAL :: Fluid Mechanics Egon Krause
INSTRUCTOR SOLUTIONS MANUAL :: Fluid Mechanics Fundamentals and Applications by 
Çengel & Cimbala
INSTRUCTOR SOLUTIONS MANUAL :: Fluid Mechanics with Engineering Applications, 
10th Edition, by Finnemore
INSTRUCTOR SOLUTIONS MANUAL :: Foundations of Applied Combinatorics by Bender, 
Williamson
INSTRUCTOR SOLUTIONS MANUAL :: Foundations of Colloid Science 2e , Hunter
INSTRUCTOR SOLUTIONS MANUAL :: Foundations of Modern Macroeconomics 2nd  Ed by 
Heijdra,  Reijnders, Romp
INSTRUCTOR SOLUTIONS MANUAL :: Fourier and Laplace Transform - Antwoorden
INSTRUCTOR SOLUTIONS MANUAL :: Fractal Geometry Mathematical Foundations and 
Applications, 2nd Ed Kenneth Falcone
INSTRUCTOR SOLUTIONS MANUAL :: fracture mechanics ; fundamentals and 
applications, 2E, by T.L. Anderson
INSTRUCTOR SOLUTIONS MANUAL :: From Polymers to Plastics By A.K. van der Vegt
INSTRUCTOR SOLUTIONS MANUAL :: Fundamental Methods of Mathematical Economics 
4th E by Chiang,Wainwright
INSTRUCTOR SOLUTIONS MANUAL :: Fundamental Quantum Mechanics for Engineers by 
Leon van Dommelen
INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Advanced Accounting By Fischer, 
Taylor
INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Aerodynamics ( 3 Ed., Anderson)
INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Aerodynamics (2 Ed., Anderson)
INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Aircraft Structural Analysis by 
Howard D. Curtis
INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Applied Electromagnetics (5th 
Ed., Fawwaz T. Ulaby)
INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Chemical Reaction Engineering by 
Davis
INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Complex Analysis ( 3rd Ed., E. 
Saff & Arthur Snider )
INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Computer Organization and 
Architecture by Abd-El-Barr, El-Rewini 
INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Corporate Finance 8th edition by 
Ross
INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Corporate Finance 9th edition by 
Ross
INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Corporate Finance, 4th Edition 
(Brealey, Myers, Marcus)
INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Differential Equations 7E Kent 
Nagle, B. Saff, Snider
INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Differential Equations and 
Boundary Value Problems, 6th Ed by Nagle ,Saff, Snider
INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Digital Logic with VHDL Design 
(1st Ed., Stephen Brown Vranesic)
INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Digital Signal Processing Using 
Matlab 2nd Edition by Robert J. Schilling, Sandra L. Harris
INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Electric Circuits (2nd.ed.) by 
C.K.Alexander M.N.O.Sadiku
INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Electric Circuits (4E., Charles 
Alexander & Matthew Sadiku)
INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Electromagnetics with 
Engineering Applications (Stuart Wentworth)
INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Electronic Circuit Design , Comer
INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Engineering Economics 2nd E by 
Chan S. Park
INSTRUCTOR SOLUTIONS MANUAL :: FUNDAMENTALS OF ENGINEERING ELECTROMAGNETICS, by 
DAVID CHENG
INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Engineering Thermodynamics, 5th 
Ed (Michael J. Moran, Howard N. Shapiro)
INSTRUCTOR S

Re: Good Python IDE

2013-01-06 Thread Ben Finney
Tetsuya  writes:

> BTW, vim is available also under Windows.

And this is one of the best reasons to learn either Vim or Emacs (or
both, eventually): one should not be tied to any particular OS for
access to one's development tools.

Vim and Emacs are both general-purpose, highly-extensible and -extended,
powerful editing tools. But more important than those is that they are
both free software and (partly as a result of that freedom)
well-supported by a mature community of developers.

Core programming tools, like your text editor or your team's VCS, take
significant investment. Don't needlessly squander that investment on a
tool limited to a single language, a single vendor, or a single
operating system.

-- 
 \  “All good things are cheap; all bad are very dear.” —Henry |
  `\ David Thoreau |
_o__)  |
Ben Finney

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


Re: Over 30 types of variables available in python ?

2013-01-06 Thread Terry Reedy

On 1/6/2013 6:12 PM, chaouche yacine wrote:


booleans
ints, floats, longs, complexes
strings, unicode strings
lists, tuples, dictionaries, dictionary views, sets, frozensets,
buffers, bytearrays, slices
functions, methods, code objects,modules,classes, instances, types,
nulls (there is exactly one object of type Null which is None),
tracebacks, frames
generators, iterators, xranges,
files,
memoryviews,
context managers,

These are all listed in this page
http://docs.python.org/2/library/stdtypes.html as built-in types.


They would better be called classes. Every thing is Python is an 
instance of a class. 'Iterator' and 'context manager' are protocols that 
multiple classes can follow, not classes themselves.



Am I
getting anything wrong here ? I'm a bit confused about it. I have never
seen so many types in the few programming languages I saw.


C has up to 8 integer types, Python 3 just 1. Most of the above are 
structures in C, which may or may not by typedef-ed, or classes in C++. 
If you counted all the structures and classes that come with C or C++, 
you would find a comparable number.


C stdlib has a pointer to file structure type, which is equivalent to 
Python's file class. It is true that C does not come with hashed arrays 
(sets) and hashed associative arrays (dicts), but they are often needed. 
So C programmers either reinvent the wheel or include a third-party 
library. C also has frame structure, but they are normally hidden. C 
programmers do not have easy direct access. However, virus writers learn 
to work with them ;-(.


--
Terry Jan Reedy

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


Re: Good Python IDE

2013-01-06 Thread Tim Johnson
* Tetsuya  [130106 14:43]:
> On 01/06/2013 11:13 PM, Tim Johnson wrote:
> >   Now I use vim for all of my work. I pretty-much hand-rolled my own
> >   IDE, which is typical of vimmers.
> 
> I did like you, too.
> I use vim for everything: coding in python, django, js, html, C/C++, 
> bash, even email (inside mutt, of course).
 Yes, Yes...

> Start with an empty ~/.vimrc, and then build up the configuration day by 
> day, adding one single plugin at a time, driven by your daily needs, 
> it's the better thing to do IMHO.
> Thus vim becomes a full fledged IDE for everything, and it does it 
> *your* way, not *its* way.
  :) Great minds run in the same gutter ... 

> BTW, vim is available also under Windows.
  Where I started using it.

-- 
Tim 
tim at tee jay forty nine dot com or akwebsoft dot com
http://www.akwebsoft.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ubuntu Python -dbg packages

2013-01-06 Thread Terry Reedy

On 1/6/2013 3:21 PM, Lee Harr wrote:



On 1/6/2013 8:42 AM, Lee Harr wrote:


I am using:
Ubuntu 12.10
Python 3.2.3


import has been considerably redone, and hopefully upgraded, in 3.3.



Ok, so now I tried python3.3-dbg but I don't think the pyqt
modules are compiled for 3.3 and that may be preventing
the import there.

Those extension modules would need to be compiled for
an exactly matching python interpreter, right?


For Windows visual C compiler, that is true. I do not know about gcc on 
*nix. I have gotten the impression that it is not necessarily so, except 
as the C api has changed in a way that affects the extension library. 
(Given that 3.3 is 3 months old, after 6 months of alpha/beta releases, 
and has some major improvements, it is past time for libraries that need 
recompiling to be so.)



I also have the ubuntu -dbg packages:
python3-dbg
python3-pyqt4-dbg



I don't understand why python3-dbg cannot import the PyQt4 modules...



Is PyQtr.__file__ the same here, as below?


Yes. It's the same.

Sorry, that's what I meant to show there.

$ python3
Python 3.2.3 (default, Oct 19 2012, 19:53:57)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import PyQt4
PyQt4.__file__

'/usr/lib/python3/dist-packages/PyQt4/__init__.py'







$ python3-dbg
Python 3.2.3 (default, Oct 19 2012, 19:58:54)
[GCC 4.7.2] on linux2



import PyQt4

[60323 refs]

PyQt4.__file__

'/usr/lib/python3/dist-packages/PyQt4/__init__.py'
[60323 refs]

import PyQt4.QtCore

Traceback (most recent call last):
 File "", line 1, in 
ImportError: No module named QtCore
[150996 refs]



So, python3-dbg _should_ be able to import this?


Given that python3 and python3-dbg import the same PyQt4 file, and that 
you spell PyQt4.QtCore the same (I checked), I am as surprised as you. 
Perhaps there is a bug in the import of the dbg build finding modules in 
packages, but that is so basic, that would surprise me also. Try running 
test/test_imp, _import, _importhooks, _importlib with both binaries 
(because you are looking for a different).


On Windows, with 3.3, interactively in IDLE, I get
>>> import test.test_imp as t; t.test_main()
...
Ran 29 tests in 0.134s
OK (skipped=1)
...
Ran 48 tests in 0.953s
OK (skipped=4)
...
Ran 4 tests in 0.169s
OK
...
Ran 288 tests in 1.684s
OK (skipped=2)

Note that the above invocation runs in verbose mode, so if there is a 
difference, you can find the specific test. The skips are usually system 
specific. For instance, the one skip in the first batch is


test_issue5604 (test.test_imp.ImportTests) ... skipped "can't run this 
test with mbcs as filesystem encoding"


The others were for other posix-windows differences.


Any ideas about the python3-pyqt4-dbg modules mentioned originally?


No. I stuck to what looked like might be easier.

--
Terry Jan Reedy

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


Re: Numpy outlier removal

2013-01-06 Thread Steven D'Aprano
On Sun, 06 Jan 2013 19:44:08 +, Joseph L. Casale wrote:

> I have a dataset that consists of a dict with text descriptions and 
> values that are integers. If required, I collect the values into a list 
> and create a numpy array running it through a simple routine: 
> 
> data[abs(data - mean(data)) < m * std(data)] 
>
> where m is the number of std deviations to include.

I'm not sure that this approach is statistically robust. No, let me be 
even more assertive: I'm sure that this approach is NOT statistically 
robust, and may be scientifically dubious.

The above assumes your data is normally distributed. How sure are you 
that this is actually the case?

For normally distributed data:

Since both the mean and std calculations as effected by the presence of 
outliers, your test for what counts as an outlier will miss outliers for 
data from a normal distribution. For small N (sample size), it may be 
mathematically impossible for any data point to be greater than m*SD from 
the mean. For example, with N=5, no data point can be more than 1.789*SD 
from the mean. So for N=5, m=1 may throw away good data, and m=2 will 
fail to find any outliers no matter how outrageous they are.

For large N, you will expect to find significant numbers of data points 
more than m*SD from the mean. With N=10, and m=3, you will expect to 
throw away 270 perfectly good data points simply because they are out on 
the tails of the distribution.

Worse, if the data is not in fact from a normal distribution, all bets 
are off. You may be keeping obvious outliers; or more often, your test 
will be throwing away perfectly good data that it misidentifies as 
outliers.

In other words: this approach for detecting outliers is nothing more than 
a very rough, and very bad, heuristic, and should be avoided.

Identifying outliers is fraught with problems even for experts. For 
example, the ozone hole over the Antarctic was ignored for many years 
because the software being used to analyse it misidentified the data as 
outliers.

The best general advice I have seen is:

Never automatically remove outliers except for values that are physically 
impossible (e.g. "baby's weight is 95kg", "test score of 31 out of 20"), 
unless you have good, solid, physical reasons for justifying removal of 
outliers. Other than that, manually remove outliers with care, or not at 
all, and if you do so, always report your results twice, once with all 
the data, and once with supposed outliers removed.

You can read up more about outlier detection, and the difficulties 
thereof, here:

http://www.medcalc.org/manual/outliers.php

https://secure.graphpad.com/guides/prism/6/statistics/index.htm

http://www.webapps.cee.vt.edu/ewr/environmental/teach/smprimer/outlier/outlier.html

http://stats.stackexchange.com/questions/38001/detecting-outliers-using-standard-deviations



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


Re: Numpy outlier removal

2013-01-06 Thread Paul Simon

"Steven D'Aprano"  wrote in message 
news:50ea28e7$0$30003$c3e8da3$54964...@news.astraweb.com...
> On Sun, 06 Jan 2013 19:44:08 +, Joseph L. Casale wrote:
>
>> I have a dataset that consists of a dict with text descriptions and
>> values that are integers. If required, I collect the values into a list
>> and create a numpy array running it through a simple routine:
>>
>> data[abs(data - mean(data)) < m * std(data)]
>>
>> where m is the number of std deviations to include.
>
> I'm not sure that this approach is statistically robust. No, let me be
> even more assertive: I'm sure that this approach is NOT statistically
> robust, and may be scientifically dubious.
>
> The above assumes your data is normally distributed. How sure are you
> that this is actually the case?
>
> For normally distributed data:
>
> Since both the mean and std calculations as effected by the presence of
> outliers, your test for what counts as an outlier will miss outliers for
> data from a normal distribution. For small N (sample size), it may be
> mathematically impossible for any data point to be greater than m*SD from
> the mean. For example, with N=5, no data point can be more than 1.789*SD
> from the mean. So for N=5, m=1 may throw away good data, and m=2 will
> fail to find any outliers no matter how outrageous they are.
>
> For large N, you will expect to find significant numbers of data points
> more than m*SD from the mean. With N=10, and m=3, you will expect to
> throw away 270 perfectly good data points simply because they are out on
> the tails of the distribution.
>
> Worse, if the data is not in fact from a normal distribution, all bets
> are off. You may be keeping obvious outliers; or more often, your test
> will be throwing away perfectly good data that it misidentifies as
> outliers.
>
> In other words: this approach for detecting outliers is nothing more than
> a very rough, and very bad, heuristic, and should be avoided.
>
> Identifying outliers is fraught with problems even for experts. For
> example, the ozone hole over the Antarctic was ignored for many years
> because the software being used to analyse it misidentified the data as
> outliers.
>
> The best general advice I have seen is:
>
> Never automatically remove outliers except for values that are physically
> impossible (e.g. "baby's weight is 95kg", "test score of 31 out of 20"),
> unless you have good, solid, physical reasons for justifying removal of
> outliers. Other than that, manually remove outliers with care, or not at
> all, and if you do so, always report your results twice, once with all
> the data, and once with supposed outliers removed.
>
> You can read up more about outlier detection, and the difficulties
> thereof, here:
>
> http://www.medcalc.org/manual/outliers.php
>
> https://secure.graphpad.com/guides/prism/6/statistics/index.htm
>
> http://www.webapps.cee.vt.edu/ewr/environmental/teach/smprimer/outlier/outlier.html
>
> http://stats.stackexchange.com/questions/38001/detecting-outliers-using-standard-deviations
>
>
>
> -- 
> Steven
If you suspect that the data may not be normal you might look at exploratory 
data analysis, see Tukey.  It's descriptive rather than analytic, treats 
outliers respectfully, uses median rather than mean, and is very visual. 
Wherever I analyzed data both gaussian and with EDA, EDA always won.

Paul 


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


Re: Numpy outlier removal

2013-01-06 Thread Oscar Benjamin
On 7 January 2013 01:46, Steven D'Aprano
 wrote:
> On Sun, 06 Jan 2013 19:44:08 +, Joseph L. Casale wrote:
>
>> I have a dataset that consists of a dict with text descriptions and
>> values that are integers. If required, I collect the values into a list
>> and create a numpy array running it through a simple routine:
>>
>> data[abs(data - mean(data)) < m * std(data)]
>>
>> where m is the number of std deviations to include.
>
> I'm not sure that this approach is statistically robust. No, let me be
> even more assertive: I'm sure that this approach is NOT statistically
> robust, and may be scientifically dubious.

Whether or not this is "statistically robust" requires more
explanation about the OP's intention. Thus far, the OP has not given
any reason/motivation for excluding data or even for having any data
in the first place! It's hard to say whether any technique applied is
really accurate/robust without knowing *anything* about the purpose of
the operation.


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


Re: PyGreSQL 4.1 released

2013-01-06 Thread D'Arcy J.M. Cain
On Sat, 5 Jan 2013 08:44:17 -0500
"D'Arcy J.M. Cain"  wrote:
> We will probably get version 4.2 released shortly and then branch 5.x
> and start working on Python 3 support.

In fact, we found a few buglets and will be releasing 4.1.1 on Tuesday.

-- 
D'Arcy J.M. Cain  |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
IM: da...@vex.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need a specific sort of string modification. Can someone help?

2013-01-06 Thread Nick Mellor
Hi Sia,

Here's another variation. It's within my tolerance for readability :-) and also 
quick, if that's an issue. It does 100,000 of your longer string in a couple of 
seconds on my venerable laptop.

It handles only single-digit numbers. For multi-digit, I'd be inclined to have 
a look at takewhile and/or dropwhile, both in itertools (Python 2.7 and 3.x 
only.)


from string import maketrans

class redux:

def __init__(self):
   intab = '+-'
   outtab = '  ' # two spaces
   self.trantab = maketrans(intab, outtab)


def reduce_plusminus(self, s):
list_form = [r[int(r[0]) + 1:] if r[0].isdigit() else r
for r
in s.translate(self.trantab).split()]
return ''.join(list_form)

if __name__ == "__main__":
p = redux()
print p.reduce_plusminus(".+3ACG.+5CAACG.+3ACG.+3ACG")
print p.reduce_plusminus("tA.-2AG.-2AG,-2ag")

for n in range(10): p.reduce_plusminus(".+3ACG.+5CAACG.+3ACG.+3ACG")

On Saturday, 5 January 2013 19:35:26 UTC+11, Sia  wrote:
> I have strings such as:
> 
> 
> 
> tA.-2AG.-2AG,-2ag
> 
> or
> 
> .+3ACG.+5CAACG.+3ACG.+3ACG
> 
> 
> 
> The plus and minus signs are always followed by a number (say, i). I want 
> python to find each single plus or minus, remove the sign, the number after 
> it and remove i characters after that. So the two strings above become:
> 
> 
> 
> tA..,
> 
> and
> 
> ...
> 
> 
> 
> How can I do that?
> 
> Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


INSTRUCTOR SOLUTIONS MANUAL :: Chemical, Biochemical, and Engineering Thermodynamics, 4th Ed by Sandler

2013-01-06 Thread ronaldmanualsea
Here are instructor's solutions manuals to the scientific textbooks in PDF 
format. They cover solutions to all problems. If you need any, let me know its 
title, edition and author. 
If your title is not listed here don't worry because it is a list of some.. 
NOTE: This service is NOT free, and Don't reply here, 
instead send an email to: 
ronaldmanualsea( at )gmail(dot)com.

INSTRUCTOR SOLUTIONS MANUAL :: Intermediate Algebra - Concepts & Applications 
8th Ed by Bittinger, Ellenbogen
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Accounting 3rd Ed by Marriott, 
Mellett
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Algorithms, 2nd Ed by Cormen, 
Leiserson 
INSTRUCTOR SOLUTIONS MANUAL :: Introduction To Analysis (3rdEd) -by William Wade
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Applied Modern Physics by Henok 
Abebe
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Chemical Engineering 
Thermodynamics (7th Ed., Smith & Van Ness)
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Commutative Algebra by M. F. 
Atiyah
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Digital Signal Processing (in 
Serbian) by Lj. Milic and Z. Dobrosavljevic
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Econometrics (2nd ed., James H. 
Stock & Mark W. Watson)
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Electric Circuits 7th Edition by 
Dorf, Svaboda
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Electric Circuits, 6E, Dorf
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Electrodynamics (3rd Ed., David 
J. Griffiths)
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Elementary Particles 2nd Ed by 
David Griffiths
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Environmental Engineering and 
Science (3rd Ed., Gilbert M. Masters & Wendell P. Ela)
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Environmental Engineering and 
Science, Edition 2, Masters
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Ergonomics 2E by Robert Bridger
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Fluid Mechanics ( 7 E., Robert 
Fox, Alan McDonald & Philip )
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Fluid Mechanics (6E., Robert 
Fox, Alan McDonald & Philip)
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to fluid mechanics 5th edition by 
Alan T. McDonald, Robert W Fox
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Graph Theory 2E - West
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Heat Transfer by Vedat S. 
Arpaci, Ahmet Selamet, Shu-Hsin Kao
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Java Programming, Comprehensive 
Version 7th Ed by  Liang
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Linear Algebra, 3rd Ed., by 
Gilbert Strang
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Management Accounting, 14 ED by 
Horngren, Schatzberg 
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Materials Science for Engineers 
(6th Ed., Shackelford)
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Materials Science for Engineers 
7th E by Shackelford
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Mathematical Statistics (6th 
Ed., Hogg, Craig & McKean)
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Mechatronics and Measurements 
Systems 2nd Ed by Alciatore, Histand
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Nuclear And Particle Physics 2nd 
E by Bromberg, Das, Ferbel
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Operations Research - 7th ed by 
Frederick Hillier, Gerald Lieberman
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Probability 2nd Ed by Bertsekas 
and Tsitsiklis
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Probability by Dimitri P. 
Bertsekas and John N. Tsitsiklis
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Probability by Grinstead, Snell
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Quantum Mechanics (2nd Ed., 
David J. Griffiths)
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Quantum Mechanics 1st edition 
(1995) by David J. Griffiths
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Queueing Theory 2nd Edition by 
R.B. Cooper
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Scientific Computation and 
Programming, 1st Edition by Daniel Kaplan
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Signal Processing by S. J. 
Orfanidis
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Signal Processing by Sophocles 
J. Orfanidis
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Solid State Physics 8th Ed by 
Kittel & Charles
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Statistical Physics by Kerson 
Huang
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Statistical Quality Control (5th 
Ed., Douglas C. Montgomery)
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to the Theory of Computation by 
Ching Law
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to the Thermodynamics of Materials 
3 E by Gaskell
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Thermal Systems Engineering 
Moran Shapiro Munson
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to VLSI Circuits and Systems, by 
John P. Uyemura
INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Wireless Systems by P.M Shankar
INSTRUC

Re: Need a specific sort of string modification. Can someone help?

2013-01-06 Thread Nick Mellor
Hi Sia,

Find a multi-digit method in this version:

from string import maketrans
from itertools import takewhile

def is_digit(s): return s.isdigit()

class redux:

def __init__(self):
   intab = '+-'
   outtab = '  '
   self.trantab = maketrans(intab, outtab)


def reduce_plusminus(self, s):
list_form = [r[int(r[0]) + 1:] if r[0].isdigit() else r
for r
in s.translate(self.trantab).split()]
return ''.join(list_form)

def reduce_plusminus_multi_digit(self, s):
spl = s.translate(self.trantab).split()
digits = [list(takewhile(is_digit, r))
   for r
   in spl]
numbers = [int(''.join(r)) if r else 0
   for r
in digits]
skips = [len(dig) + num for dig, num in zip(digits, numbers)]
return ''.join([s[r:] for r, s in zip(skips, spl)])

if __name__ == "__main__":
p = redux()
print p.reduce_plusminus(".+3ACG.+5CAACG.+3ACG.+3ACG")
print p.reduce_plusminus("tA.-2AG.-2AG,-2ag")
print 'multi-digit...'
print p.reduce_plusminus_multi_digit(".+3ACG.+5CAACG.+3ACG.+3ACG")
print p.reduce_plusminus_multi_digit(".+12ACGACGACGACG.+5CAACG.+3ACG.+3ACG")


HTH,

Nick

On Saturday, 5 January 2013 19:35:26 UTC+11, Sia  wrote:
> I have strings such as:
> 
> 
> 
> tA.-2AG.-2AG,-2ag
> 
> or
> 
> .+3ACG.+5CAACG.+3ACG.+3ACG
> 
> 
> 
> The plus and minus signs are always followed by a number (say, i). I want 
> python to find each single plus or minus, remove the sign, the number after 
> it and remove i characters after that. So the two strings above become:
> 
> 
> 
> tA..,
> 
> and
> 
> ...
> 
> 
> 
> How can I do that?
> 
> Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Numpy outlier removal

2013-01-06 Thread Steven D'Aprano
On Mon, 07 Jan 2013 02:29:27 +, Oscar Benjamin wrote:

> On 7 January 2013 01:46, Steven D'Aprano
>  wrote:
>> On Sun, 06 Jan 2013 19:44:08 +, Joseph L. Casale wrote:
>>
>>> I have a dataset that consists of a dict with text descriptions and
>>> values that are integers. If required, I collect the values into a
>>> list and create a numpy array running it through a simple routine:
>>>
>>> data[abs(data - mean(data)) < m * std(data)]
>>>
>>> where m is the number of std deviations to include.
>>
>> I'm not sure that this approach is statistically robust. No, let me be
>> even more assertive: I'm sure that this approach is NOT statistically
>> robust, and may be scientifically dubious.
> 
> Whether or not this is "statistically robust" requires more explanation
> about the OP's intention. 

Not really. Statistics robustness is objectively defined, and the user's 
intention doesn't come into it. The mean is not a robust measure of 
central tendency, the median is, regardless of why you pick one or the 
other.

There are sometimes good reasons for choosing non-robust statistics or 
techniques over robust ones, but some techniques are so dodgy that there 
is *never* a good reason for doing so. E.g. finding the line of best fit 
by eye, or taking more and more samples until you get a statistically 
significant result. Such techniques are not just non-robust in the 
statistical sense, but non-robust in the general sense, if not outright 
deceitful.



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


Re: Need a specific sort of string modification. Can someone help?

2013-01-06 Thread Nick Mellor
Note that the multi-line version above tolerates missing digits: if the number 
is missing after the '+/-' it doesn't skip any letters.

Brief explanation of the multi-digit version:

+/- are converted to spaces and used to split the string into sections. The 
split process effectively swallows the +/- characters.

The complication of multi-digits is that you need to skip the (possibly 
multiple) digits, which adds another stage to the calculation. In:

+3ACG. -> .

you skip 1 + 3 characters, 1 for the digit, 3 for the following letters as 
specified by the digit 3. In:

-11ACGACGACGACG. -> G.

You skip 2 + 11 characters, 2 digits in "12" and 11 letters following. And 
incidentally in:

+ACG. -> ACG.

there's no digit, so you skip 0 digits + 0 letters.

Having split on +/- using .translate() and .split() I use takewhile to separate 
the zero or more digits from the following letters. If takewhile doesn't find 
any digits at the start of the sequence, it returns the empty list []. 
''.join(list) swallows empty lists so dropwhile and ''.join() cover the 
no-digit case between them. If a lack of digits is a data error then it would 
be easy to test for-- just look for an empty list in 'digits'.

I was pleasantly surprised to find that using list comprehensions, zip, join 
(all highly optimised in Python) and several intermediate lists still works at 
a fairly decent speed, despite using more stages to handle multi-digits. But it 
is about 4x slower than the less flexible 1-digit version on my hardware (about 
25,000 per second.)

Nick

On Monday, 7 January 2013 14:40:02 UTC+11, Nick Mellor  wrote:
> Hi Sia,
> 
> 
> 
> Find a multi-digit method in this version:
> 
> 
> 
> from string import maketrans
> 
> from itertools import takewhile
> 
> 
> 
> def is_digit(s): return s.isdigit()
> 
> 
> 
> class redux:
> 
> 
> 
> def __init__(self):
> 
>intab = '+-'
> 
>outtab = '  '
> 
>self.trantab = maketrans(intab, outtab)
> 
> 
> 
> 
> 
> def reduce_plusminus(self, s):
> 
> list_form = [r[int(r[0]) + 1:] if r[0].isdigit() else r
> 
> for r
> 
> in s.translate(self.trantab).split()]
> 
> return ''.join(list_form)
> 
> 
> 
> def reduce_plusminus_multi_digit(self, s):
> 
> spl = s.translate(self.trantab).split()
> 
> digits = [list(takewhile(is_digit, r))
> 
>for r
> 
>in spl]
> 
> numbers = [int(''.join(r)) if r else 0
> 
>for r
> 
> in digits]
> 
> skips = [len(dig) + num for dig, num in zip(digits, numbers)]
> 
> return ''.join([s[r:] for r, s in zip(skips, spl)])
> 
> 
> 
> if __name__ == "__main__":
> 
> p = redux()
> 
> print p.reduce_plusminus(".+3ACG.+5CAACG.+3ACG.+3ACG")
> 
> print p.reduce_plusminus("tA.-2AG.-2AG,-2ag")
> 
> print 'multi-digit...'
> 
> print p.reduce_plusminus_multi_digit(".+3ACG.+5CAACG.+3ACG.+3ACG")
> 
> print 
> p.reduce_plusminus_multi_digit(".+12ACGACGACGACG.+5CAACG.+3ACG.+3ACG")
> 
> 
> 
> 
> 
> HTH,
> 
> 
> 
> Nick
> 
> 
> 
> On Saturday, 5 January 2013 19:35:26 UTC+11, Sia  wrote:
> 
> > I have strings such as:
> 
> > 
> 
> > 
> 
> > 
> 
> > tA.-2AG.-2AG,-2ag
> 
> > 
> 
> > or
> 
> > 
> 
> > .+3ACG.+5CAACG.+3ACG.+3ACG
> 
> > 
> 
> > 
> 
> > 
> 
> > The plus and minus signs are always followed by a number (say, i). I want 
> > python to find each single plus or minus, remove the sign, the number after 
> > it and remove i characters after that. So the two strings above become:
> 
> > 
> 
> > 
> 
> > 
> 
> > tA..,
> 
> > 
> 
> > and
> 
> > 
> 
> > ...
> 
> > 
> 
> > 
> 
> > 
> 
> > How can I do that?
> 
> > 
> 
> > Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need a specific sort of string modification. Can someone help?

2013-01-06 Thread Nick Mellor
Oops!

"You skip 2 + 11 characters, 2 digits in "12" and 11 letters following. And 
incidentally in: "

should read:

"You skip 2 + 11 characters, 2 digits in "11" and 11 letters following. And 
incidentally in: "

N

On Saturday, 5 January 2013 19:35:26 UTC+11, Sia  wrote:
> I have strings such as:
> 
> 
> 
> tA.-2AG.-2AG,-2ag
> 
> or
> 
> .+3ACG.+5CAACG.+3ACG.+3ACG
> 
> 
> 
> The plus and minus signs are always followed by a number (say, i). I want 
> python to find each single plus or minus, remove the sign, the number after 
> it and remove i characters after that. So the two strings above become:
> 
> 
> 
> tA..,
> 
> and
> 
> ...
> 
> 
> 
> How can I do that?
> 
> Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need a specific sort of string modification. Can someone help?

2013-01-06 Thread John Ladasky
On Saturday, January 5, 2013 12:35:26 AM UTC-8, Sia wrote:
> I have strings such as:
>
> tA.-2AG.-2AG,-2ag
> 
> .+3ACG.+5CAACG.+3ACG.+3ACG

Just curious, do these strings represent DNA sequences?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to python, do I need an IDE or is vim still good enough?

2013-01-06 Thread Wayne Werner

On Fri, 4 Jan 2013, Roy Smith wrote:


In article ,
Cameron Simpson  wrote:


On 01/04/13 01:34, Anssi Saari wrote:
| Just curious since I read the same thing in a programming book recently
| (21st century C). So what's the greatness that terminal multiplexors
| offer over tabbed terminals? Especially for software development?


There's no doubt that you need access to multiple terminal sessions.
Whether you achieve that with multiple terminal windows on your desktop,
multiple desktops, tabbed terminals, or something like screen is
entirely personal preference.


+1

I use a tiling WM (awesomewm), but I still find that tmux has its place. 
Usually I'll have a terminal per box that I'm working on, and a tmux 
session within that.


This allows me to detach and reattach from any system I'm on. In addition, 
if I lose my connection, I don't have to figure out which processes I had 
in bg. There's also the neat ability (at least with tmux - I haven't used 
screen for a while now) to work across sessions - so I might have a 
personal session (with things like alpine and irssi), a dev session (with 
Vim, a python prompt, and a shell) - and I can either keep them separate 
if I need to focus, or join the windows if I need some help.


One thing that I've noticed that tmux does poorly is handle the mouse for 
selecting. And as I haven't yet written or found a cross-platform/machine 
clipboard manager, using the tmux copy or xclip doesn't really help that 
much :P


I'd say the main benefit (aside from tiling) is the attach/detach. Unless 
your machine powers off or you kill tmux/screen, your sessions will stay 
around.


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


Re: Help Support Python

2013-01-06 Thread kalpanaganeshm
Informatics Outsourcing is an Offshore Intellectual Property Services company. 
They are providing Intellectual Property services for Bio Technology, 
Biochemistry, Drug Discovery, Chemistry, etc
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need a specific sort of string modification. Can someone help?

2013-01-06 Thread Nick Mellor
Hi Sia, 

Thanks for the problem! I hope you find these examples understandable.

Below, find an inflexible but fairly fast single-digit method and a slower (but 
still respectable) multi-digit method that copes with entirely absent digits 
after +/- and multi-digit skips such as 12 or 37 or 186 following letters 
rather than just 3 or 5 or 9. Not knowing your problem domain I'm not sure if 
these larger skips are likely or even possible, nor whether it's likely that 
there will be no digit.

Neither method flags the edge case where there are not enough letters to skip 
before the next +/-. They just swallow that chunk of the string entirely 
without error. Is that a problem?

Python 2.7 or later.

from string import maketrans
from itertools import takewhile

# function used by takewhile to detect digits
def is_digit(s): return s.isdigit()

class redux:

def __init__(self):
   intab = '+-'
   outtab = '  '
   self.trantab = maketrans(intab, outtab)


# simple-minded, fast, 1-digit algorithm
def reduce_plusminus(self, s):
list_form = [r[int(r[0]) + 1:] if r[0].isdigit() else r
for r
in s.translate(self.trantab).split()]
return ''.join(list_form)

# multi-digit algorithm
def reduce_plusminus_multi_digit(self, s):
chunks = s.translate(self.trantab).split()
digits = [list(takewhile(is_digit, r))
   for r
   in chunks]
# zero case ('else 0') is for missing digit(s)
numbers = [int(''.join(r)) if r else 0
   for r
in digits]
# how far to skip (number and skipped letters)
skips = [len(dig) + num
 for dig, num
 in zip(digits, numbers)]
return ''.join([sequence[skipover:]
for skipover, sequence
in zip(skips, chunks)])

if __name__ == "__main__":
p = redux()
print (p.reduce_plusminus(".+3ACG.+5CAACG.+3ACG.+3ACG"))
print (p.reduce_plusminus("tA.-5AG.-2AG,-2ag"))
print ('multi-digit...')
print (p.reduce_plusminus_multi_digit(".+3ACG.+5CAACG.+3ACG.+3ACG"))
print 
(p.reduce_plusminus_multi_digit(".+12ACGACGACGACG.+5CAACG.+3ACG.+3ACG"))
print 
(p.reduce_plusminus_multi_digit(".+12ACGACGACGACG.+5CAACG.+ACG.+3ACG"))

for n in range(10): 
p.reduce_plusminus_multi_digit(".+12ACGACGACGACG.+5CAACG.+3ACG.+3ACG")


Note that the multi-line version above tolerates missing digits: if the number 
is missing after the '+/-' it doesn't skip any letters. 

Explanation:

String slicing is good in Python, but list comprehensions are often the most 
powerful and efficient way to transform data. If you've come from another 
language or you're a newb to programming, it's well worth getting grips with 
list comprehensions [a for b in lst].

First, +/- are converted to spaces. Splitting the string into a list, breaking 
at spaces, effectively swallows the +/- characters and leaves us with chunks of 
string from which to drop the specified number of letters. Having dropped the 
letters, we convert the transformed list back into a string.

The single-digit version just assumes that the number is always present and 
always single-digit. If you allow multi-digits be ready to skip those multiple 
digits, as well as skipping letters, adding another stage to the calculation. 
E.g. in: 

+3ACG. -> . 

you skip 1 + 3 characters, 1 for the digit, 3 for the following letters as 
specified by the digit 3. In: 

-11ACGACGACGACG. -> G. 

You skip 2 + 11 characters, 2 characters in "11" and 11 characters following. 
And incidentally in: 

+ACG. -> ACG. 

there's no digit, so you skip 0 digits + 0 letters. If a lack of digits is a 
data error then it would be easy to test for-- just look for an empty list in 
the 'digits' list.

For each chunk (stuff between +/-) I use takewhile to separate the zero or more 
initial digits from the following letters. itertools.takewhile is a nice tool 
for matching stuff until the first time a condition ceases to hold. In this 
case I'm matching digits up until the first non-digit.

If takewhile doesn't find any digits at the start of the sequence, it returns 
the empty list []. ''.join(list) swallows empty lists so takewhile and 
''.join() do behind-the-scenes leg-work for me in detecting the case of absent 
digit(s).

For my money speed isn't bad for these two methods (again, I don't know your 
domain.) On my (ancient) hardware the 1-digit version does over 100,000/s for 
your longer string, the multi-digit about 35,000/s.

HTH,

Nick

On Saturday, 5 January 2013 19:35:26 UTC+11, Sia  wrote:
> I have strings such as:
> 
> 
> 
> tA.-2AG.-2AG,-2ag
> 
> or
> 
> .+3ACG.+5CAACG.+3ACG.+3ACG
> 
> 
> 
> The plus and minus signs are always followed by a number (say, i). I want 
> python to find each single plus or minus, remove the sign, the number after 
> it and remove i characters after that. So the