python financial data cleaning

2015-06-15 Thread Sebastian M Cheung via Python-list
How to do financial data cleaning ? Say I assume a list of 1000 finance series 
data in myList = Open, High, Low and Close. For missing Close Price data, What 
is best practice to clean data in Python

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


Re: python financial data cleaning

2015-06-15 Thread Mark Lawrence

On 15/06/2015 11:12, Sebastian M Cheung via Python-list wrote:

How to do financial data cleaning ? Say I assume a list of 1000 finance series 
data in myList = Open, High, Low and Close. For missing Close Price data, What 
is best practice to clean data in Python



http://pandas.pydata.org/

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: python financial data cleaning

2015-06-15 Thread Sebastian M Cheung via Python-list
On Monday, June 15, 2015 at 11:13:07 AM UTC+1, Sebastian M Cheung wrote:
> How to do financial data cleaning ? Say I assume a list of 1000 finance 
> series data in myList = Open, High, Low and Close. For missing Close Price 
> data, What is best practice to clean data in Python

Thanks Mark just looking into Pandas now



Seb
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Keypress Input

2015-06-15 Thread Oscar Benjamin
On 15 June 2015 at 06:23, John McKenzie  wrote:
>
>  Thank to the others who joined in and posted replies.
>
>  Michael, your assumption is correct. To quote my original post, "and I
> want this working on a Raspberry Pi." Doing a superficial look at curses
> and getch it looks excessively complicated. I was under the impression it
> was not multi-platform and Linux was excluded. Searching for getch and
> raspberry pi on the web I see it is not and is available for Raspian.

I'm not sure what you mean but you can write a getch function for
Unixy systems using the tty module (I can't remember where I
originally borrowed this code from):

import sys, tty, termios

def getch():
fd = sys.stdin.fileno()
oldsettings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
c = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, oldsettings)
return c

while True:
key = getch()
print("key: '%c'  code: '%d'" % (key, ord(key)))
if key == 'q':
break

This puts the terminal in "raw mode" and waits for a key-press. Once a
key is pressed the terminal is restored to it's previous mode (most
likely not raw mode) and the character is returned. This is important
because once your program finishes you don't want the terminal to be
in raw mode. If the terminal goes weird you can usually fix it by
typing "reset" and pressing enter.

Note that going into raw mode has other implications such as not being
able to exit your program with ctrl-c or suspend with ctrl-z etc. You
can explicitly process those kinds of contrl keys with something like:

while True:
key = getch()
if 1 <= ord(key) <= 26:
ctrl_key = chr(ord(key) + 64)
print("ctrl-%c" % ctrl_key)
if ctrl_key == 'C':
break
else:
print("key: '%c'" % key)


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


Re: python financial data cleaning

2015-06-15 Thread Laura Creighton
I don't know anything about this program, and in particular how
complete it is, but worth a look
https://github.com/benjaminmgross/clean-fin-data

Laura
-- 
https://mail.python.org/mailman/listinfo/python-list


Creating .exe file in Python

2015-06-15 Thread subhabrata . banerji
Dear Group,

I am trying to learn how to create .exe file for Python. I tried to work around 
http://www.py2exe.org/index.cgi/Tutorial of Py2exe. The sample program went 
nice.
But if I try to make exe for larger programs with methods and classes I am 
getting error. 

If any one of the esteemed members may kindly suggest how to work out. 
I am using Python2.7+ on Windows 7 Professional. 

Regards,
Subhabrata Banerjee. 

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


Re: Creating .exe file in Python

2015-06-15 Thread Mark Lawrence

On 15/06/2015 12:42, subhabrata.bane...@gmail.com wrote:

Dear Group,

I am trying to learn how to create .exe file for Python. I tried to work around
http://www.py2exe.org/index.cgi/Tutorial of Py2exe. The sample program went 
nice.
But if I try to make exe for larger programs with methods and classes I am 
getting error.

If any one of the esteemed members may kindly suggest how to work out.
I am using Python2.7+ on Windows 7 Professional.

Regards,
Subhabrata Banerjee.



I'm awfully sorry but both my main and backup crystal balls are being 
repaired due to overuse.  "I am getting error" is about as much use as a 
wet fart in a thunderstorm.  So given that I never much liked guessing 
games anyway as I'm not much good at them, how about telling us 
precisely what error you're getting.  In that way one or more of our 
most esteemed colleagues might be able to help.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Creating .exe file in Python

2015-06-15 Thread Laura Creighton
In a message of Mon, 15 Jun 2015 04:42:09 -0700, subhabrata.bane...@gmail.com w
rites:
>Dear Group,
>
>I am trying to learn how to create .exe file for Python. I tried to work 
>around 
>http://www.py2exe.org/index.cgi/Tutorial of Py2exe. The sample program went 
>nice.
>But if I try to make exe for larger programs with methods and classes I am 
>getting error. 
>
>If any one of the esteemed members may kindly suggest how to work out. 
>I am using Python2.7+ on Windows 7 Professional. 
>
>Regards,
>Subhabrata Banerjee. 

1. Post the error.

2. I have always had better luck with PyInstaller than with py2exe
   https://github.com/pyinstaller/pyinstaller/wiki

Laura

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


Re: Get classes from "self.MyClass" to improve subclassability

2015-06-15 Thread Thomas Güttler
Hi,

crazy. I develop python since several years. I was not aware, that you can 
change the defaults of kwargs. I am amazed, but won't use it :-)



Am Samstag, 13. Juni 2015 01:09:47 UTC+2 schrieb Terry Reedy:
> On 6/12/2015 7:12 AM, Thomas Güttler wrote:
> > Here is a snippet from the argparse module:
> >
> > {{{
> >  def parse_known_args(self, args=None, namespace=None):
> >  ...
> >  # default Namespace built from parser defaults
> >  if namespace is None:
> >  namespace = Namespace() # < === my issue
> > }}}
> >
> > I subclass from the class of the above snippet.
> >
> > I would like to use a different Namespace class.
> >
> > if the above could would use
> >
> >  namespace = self.Namespace()
> >
> > it would be very easy for me to inject a different Namespace class.
> 
> The default arg (None) for the namespace parameter of the 
> parse_known_args is an attribute of the function, not of the class or 
> instance thereof.  Unless the default Namespace is used elsewhere, this 
> seems sensible.
> 
> In CPython, at least, and probably in pypy, you can change this 
> attribute.  (But AFAIK, this is not guaranteed in all implementations.)
> 
>  >>> def f(n = 1): pass
> 
>  >>> f.__defaults__
> (1,)
>  >>> f.__defaults__ = (2,)
>  >>> f.__defaults__
> (2,)
> 
> So the following works
> 
>  >>> class C():
>   def f(n=1): print(n)
>   
>  >>> class D(C):
>   C.f.__defaults__ = (2,)
>   
>  >>> D.f()
> 2
> 
> Of course, this may or may not do more than you want.
> 
>  >>> C.f()
> 2
> 
> -- 
> Terry Jan Reedy

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


Re: Creating .exe file in Python

2015-06-15 Thread subhabrata . banerji
On Monday, June 15, 2015 at 6:32:33 PM UTC+5:30, Laura Creighton wrote:
> In a message of Mon, 15 Jun 2015 04:42:09 -0700,  w
> rites:
> >Dear Group,
> >
> >I am trying to learn how to create .exe file for Python. I tried to work 
> >around 
> >http://www.py2exe.org/index.cgi/Tutorial of Py2exe. The sample program went 
> >nice.
> >But if I try to make exe for larger programs with methods and classes I am 
> >getting error. 
> >
> >If any one of the esteemed members may kindly suggest how to work out. 
> >I am using Python2.7+ on Windows 7 Professional. 
> >
> >Regards,
> >Subhabrata Banerjee. 
> 
> 1. Post the error.
> 
> 2. I have always had better luck with PyInstaller than with py2exe
>https://github.com/pyinstaller/pyinstaller/wiki
> 
> Laura
Dear Group,

I wrote a script as NLQ3. py 

the code is written as, 

import nltk
import itertools 
def nlq3(n):
inp=raw_input("Print Your Query:")
tag=nltk.pos_tag(nltk.wordpunct_tokenize(inp))
print "The Tagged Value Is:",tag
noun=[word[0] for word in tag if 'NN' in word[1]]
#print noun
#COMBINATION OF ALL ELEMENTS
for i in xrange(1,len(noun)+1):
comb= list(itertools.combinations(noun,i))
for i,v in enumerate(comb):
#print v
v1=list(v)
print v1

I tried to call it as,
C:\Tutorial>python hello.py
...
as 

C:\Python27>python NLQ3.py

C:\Python27>

But I am not getting any output.

Next I tried to create setup.py as,

from distutils.core import setup
import py2exe
setup(console=['NLQ3.py'])

and trying to work out as,


C:\Python27>python setup.py install
running install
running build
running install_egg_info
Removing C:\Python27\Lib\site-packages\UNKNOWN-0.0.0-py2.7.egg-info
Writing C:\Python27\Lib\site-packages\UNKNOWN-0.0.0-py2.7.egg-info

C:\Python27>

Now, 
as I am giving 
C:\Python27>python setup.py py2exe

it is giving me the following result,
running py2exe
*** searching for required modules ***
*** parsing results ***
creating python loader for extension 'scipy.optimize.minpack2' (C:\Python27\lib\
site-packages\scipy\optimize\minpack2.pyd -> scipy.optimize.minpack2.pyd)
creating python loader for extension 'numpy.core.umath' (C:\Python27\lib\site-pa
ckages\numpy\core\umath.pyd -> numpy.core.umath.pyd)
creating python loader for extension '_elementtree' (C:\Python27\DLLs\_elementtr
ee.pyd -> _elementtree.pyd)
creating python loader for extension 'matplotlib._path' (C:\Python27\lib\site-pa
ckages\matplotlib\_path.pyd -> matplotlib._path.pyd)
creating python loader for extension 'numpy.fft.fftpack_lite' (C:\Python27\lib\s
ite-packages\numpy\fft\fftpack_lite.pyd -> numpy.fft.fftpack_lite.pyd)
creating python loader for extension 'numpy.lib._compiled_base' (C:\Python27\lib
\site-packages\numpy\lib\_compiled_base.pyd -> numpy.lib._compiled_base.pyd)
creating python loader for extension 'scipy.optimize._minpack' (C:\Python27\lib\
site-packages\scipy\optimize\_minpack.pyd -> scipy.optimize._minpack.pyd)
creating python loader for extension '_ctypes' (C:\Python27\DLLs\_ctypes.pyd ->
_ctypes.pyd)
creating python loader for extension 'scipy.sparse.linalg.isolve._iterative' (C:
\Python27\lib\site-packages\scipy\sparse\linalg\isolve\_iterative.pyd -> scipy.s
parse.linalg.isolve._iterative.pyd)
creating python loader for extension 'sklearn.linear_model.sgd_fast' (C:\Python2
7\lib\site-packages\sklearn\linear_model\sgd_fast.pyd -> sklearn.linear_model.sg
d_fast.pyd)
creating python loader for extension 'scipy.stats._rank' (C:\Python27\lib\site-p
ackages\scipy\stats\_rank.pyd -> scipy.stats._rank.pyd)
creating python loader for extension 'select' (C:\Python27\DLLs\select.pyd -> se
lect.pyd)
creating python loader for extension 'scipy.sparse.csgraph._reordering' (C:\Pyth
on27\lib\site-packages\scipy\sparse\csgraph\_reordering.pyd -> scipy.sparse.csgr
aph._reordering.pyd)
creating python loader for extension 'unicodedata' (C:\Python27\DLLs\unicodedata
.pyd -> unicodedata.pyd)
creating python loader for extension 'scipy.special.specfun' (C:\Python27\lib\si
te-packages\scipy\special\specfun.pyd -> scipy.special.specfun.pyd)
creating python loader for extension 'scipy.spatial.qhull' (C:\Python27\lib\site
-packages\scipy\spatial\qhull.pyd -> scipy.spatial.qhull.pyd)
creating python loader for extension 'scipy.interpolate._ppoly' (C:\Python27\lib
\site-packages\scipy\interpolate\_ppoly.pyd -> scipy.interpolate._ppoly.pyd)
creating python loader for extension 'scipy.sparse.csgraph._tools' (C:\Python27\
lib\site-packages\scipy\sparse\csgraph\_tools.pyd -> scipy.sparse.csgraph._tools
.pyd)
creating python loader for extension 'scipy.interpolate.dfitpack' (C:\Python27\l
ib\site-packages\scipy\interpolate\dfitpack.pyd -> scipy.interpolate.dfitpack.py
d)
creating python loader for extension 'scipy.linalg._fblas' (C:\Python27\lib\site
-packages\scipy\linalg\_fblas.pyd -> scipy.linalg._fblas.pyd)
creating python loader for extension 'scipy.optimize._zeros' (C:\Python27\lib\si
te-packages\scipy\optimize\

Re: python financial data cleaning

2015-06-15 Thread Sebastian M Cheung via Python-list
On Monday, June 15, 2015 at 12:35:18 PM UTC+1, Laura Creighton wrote:
> I don't know anything about this program, and in particular how
> complete it is, but worth a look
> https://github.com/benjaminmgross/clean-fin-data
> 
> Laura

Thanks Laura, I will check it out, but basically it is to clean financial 
series data as sometimes there are missing closing price data, misalignment of 
some sort etc 
-- 
https://mail.python.org/mailman/listinfo/python-list


Pandas SQL Update

2015-06-15 Thread chrismeek4542
I have an app that basically compares a old foxpro database to a MySQL 
database. If the time-stamp does not match up then it updates the MySQL. My 
question is, is there a more officiant way of doing the MySQL update. I am 
using pandas itterrows() then doing an update query on each iteration. There is 
100,000 plus rows to iterate over so it takes some time
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating .exe file in Python

2015-06-15 Thread subhabrata . banerji
On Monday, June 15, 2015 at 5:12:24 PM UTC+5:30, subhabrat...@gmail.com wrote:
> Dear Group,
> 
> I am trying to learn how to create .exe file for Python. I tried to work 
> around 
> http://www.py2exe.org/index.cgi/Tutorial of Py2exe. The sample program went 
> nice.
> But if I try to make exe for larger programs with methods and classes I am 
> getting error. 
> 
> If any one of the esteemed members may kindly suggest how to work out. 
> I am using Python2.7+ on Windows 7 Professional. 
> 
> Regards,
> Subhabrata Banerjee.

I am also experimenting around Pyinstaller, cx_Freeze and Inno Studio. But not 
finding ample examples and manuals. 
Regards,
Subhabrata. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating .exe file in Python

2015-06-15 Thread Thierry Chappuis

Hi,

The question is why to you want to create an exe from your python project?

Setuptools is capable to create small .exe launchers in the Scripts dir of 
your

python install. These launchers start a python script and use the python
interpreter registered on your platform. That's pretty light and that's my
prefered solution.

If installing the Python interpreter is an issue for the end user, we can 
make
the installer do it for him. Installer programs like Inno Setup let you do 
it

quite easily.

Kind regards

Thierry


On lun., juin 15, 2015 at 4:10 PM, < subhabrata.bane...@gmail.com 
[subhabrata.bane...@gmail.com] > wrote:
On Monday, June 15, 2015 at 5:12:24 PM UTC+5:30, subhabrat...@gmail.com 
wrote:

> Dear Group,
>
> I am trying to learn how to create .exe file for Python. I tried to work
around
> http://www.py2exe.org/index.cgi/Tutorial of Py2exe. The sample program 
went

nice.
> But if I try to make exe for larger programs with methods and classes I 
am

getting error.
>
> If any one of the esteemed members may kindly suggest how to work out.
> I am using Python2.7+ on Windows 7 Professional.
>
> Regards,
> Subhabrata Banerjee.

I am also experimenting around Pyinstaller, cx_Freeze and Inno Studio. But 
not

finding ample examples and manuals.
Regards,
Subhabrata.
--
https://mail.python.org/mailman/listinfo/python-list-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating .exe file in Python

2015-06-15 Thread subhabrata . banerji
On Monday, June 15, 2015 at 8:02:21 PM UTC+5:30, Thierry Chappuis wrote:
> Hi,
> 
> The question is why to you want to create an exe from your 
> python project?
> 
> Setuptools is capable to create small .exe launchers in the 
> Scripts dir of your python install. These launchers start a python script 
> and use the python interpreter registered on your platform. That's pretty 
> light and that's my prefered solution.
> 
> If installing the Python interpreter is an issue for the end 
> user, we can make the installer do it for him. Installer programs like Inno 
> Setup let you do it quite easily.
> 
> Kind regards
> 
> Thierry
> 
> 
> 
> On lun., juin 15, 2015 at 
> 4:10 PM,   
> wrote:
> 
> 
> On Monday, June 15, 2015 at 
> 5:12:24 PM UTC+5:30, subhabrat...@gmail.com wrote:
> 
> 
> > Dear Group,
> 
> 
> > 
> 
> 
> > I am trying to learn how to create .exe file for Python. I tried to 
> work around 
> 
> 
> > http://www.py2exe.org/index.cgi/Tutorial of Py2exe. The sample program 
> went nice.
> 
> 
> > But if I try to make exe for larger programs with methods and classes 
> I am getting error. 
> 
> 
> > 
> 
> 
> > If any one of the esteemed members may kindly suggest how to work out. 
> 
> 
> 
> > I am using Python2.7+ on Windows 7 Professional. 
> 
> 
> > 
> 
> 
> > Regards,
> 
> 
> > Subhabrata Banerjee.
> 
> 
> 
> 
> 
> I am also experimenting around Pyinstaller, cx_Freeze and Inno Studio. But 
> not finding ample examples and manuals. 
> 
> 
> Regards,
> 
> 
> Subhabrata. 
> 
> 
> -- 
> 
> 
> https://mail.python.org/mailman/listinfo/python-list

Thank you for your kind reply. I have downloaded it, but no good tutorial. If 
you may send any. Regards, Subhabrata Banerjee. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating .exe file in Python

2015-06-15 Thread Laura Creighton
In a message of Mon, 15 Jun 2015 06:42:48 -0700, subhabrata.bane...@gmail.com w

>I wrote a script as NLQ3. py 
>
>the code is written as, 
>
>import nltk
>import itertools 
>def nlq3(n):
>inp=raw_input("Print Your Query:")
>tag=nltk.pos_tag(nltk.wordpunct_tokenize(inp))
>print "The Tagged Value Is:",tag
>noun=[word[0] for word in tag if 'NN' in word[1]]
>#print noun
>#COMBINATION OF ALL ELEMENTS
>for i in xrange(1,len(noun)+1):
>comb= list(itertools.combinations(noun,i))
>for i,v in enumerate(comb):
>#print v
>v1=list(v)
>print v1
>
>I tried to call it as,
>C:\Tutorial>python hello.py
>...
>as 
>
>C:\Python27>python NLQ3.py
>
>C:\Python27>
>
>But I am not getting any output.

You need to fix your script first, and package it later.
That you are not getting any output indicates that you have
a severe problem.  And you do.  There is no main function in
the code that you posted.  So I made 2 small changes.

First, you aren't using n in your nlq3.  So I changed the function
definition to it to.

def nlq3():

Then I added these lines to the very bottom of the file.

if __name__ == "__main__":
nlq3()

My file is named nlq3.py and now python nlq3.py gives output.  This
is an improvement.  But the code is still wrong.

It gets to here:

 tag=nltk.pos_tag(nltk.wordpunct_tokenize(inp))

and nltk is very unhappy about this.


lac@smartwheels:~/python$ python nlq3.py
Print Your Query:hello
Traceback (most recent call last):
  File "nlq3.py", line 18, in 
nlq3()
  File "nlq3.py", line 5, in nlq3
tag=nltk.pos_tag(nltk.wordpunct_tokenize(inp))
  File "/usr/local/lib/python2.7/dist-packages/nltk/tag/__init__.py", line 103, 
in pos_tag
tagger = load(_POS_TAGGER)
  File "/usr/local/lib/python2.7/dist-packages/nltk/data.py", line 781, in load
opened_resource = _open(resource_url)
  File "/usr/local/lib/python2.7/dist-packages/nltk/data.py", line 895, in _open
return find(path_, path + ['']).open()
  File "/usr/local/lib/python2.7/dist-packages/nltk/data.py", line 624, in find
raise LookupError(resource_not_found)
LookupError: 
**
  Resource u'taggers/maxent_treebank_pos_tagger/english.pickle'
  not found.  Please use the NLTK Downloader to obtain the
  resource:  >>> nltk.download()
  Searched in:
- '/home/lac/nltk_data'
- '/usr/share/nltk_data'
- '/usr/local/share/nltk_data'
- '/usr/lib/nltk_data'
- '/usr/local/lib/nltk_data'
- u''
**

I don't know enough about nltk to know how to fix this.  You will have
to read nltk docs for that.  But get the code to work, first and
package it later, ok?

Laura
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Keypress Input

2015-06-15 Thread Grant Edwards
On 2015-06-15, Oscar Benjamin  wrote:

> Note that going into raw mode has other implications such as not
> being able to exit your program with ctrl-c or suspend with ctrl-z
> etc. You can explicitly process those kinds of contrl keys with
> something like:
>
> while True:
> key = getch()
> if 1 <= ord(key) <= 26:
> ctrl_key = chr(ord(key) + 64)
> print("ctrl-%c" % ctrl_key)
> if ctrl_key == 'C':
> break
> else:
> print("key: '%c'" % key)

It's probably better (at least on Linux) to just enable handling of
those characters in by setting the ISIG lflag:

def getch():
fd = sys.stdin.fileno()
oldsettings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())

# enable handling of ctrl-C, ctrl-Z, etc.
attr = termios.tcgetattr(fd)
attr[3] |= termios.ISIG
termios.tcsetattr(fd,termios.TCSANOW,attr)

c = sys.stdin.read(1)

finally:
termios.tcsetattr(fd, termios.TCSADRAIN, oldsettings)
return c

It would be a bit cleaner if the termios module supported the the
cfmakeraw(3) function, then you could do it this way and save a couple
of system calls:

def getch():
fd = sys.stdin.fileno()
oldsettings = termios.tcgetattr(fd)
try:
newsettings = termios.makeraw(oldsettings)
newsettings[3] |= termios.ISIG
termios.tcsetattr(fd,termios.TCSANOW,newsettings)
c = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, oldsettings)
return c

[I'm a bit surprised that after all these years using literal integers
to index into the attribute list is the "right" way.]

-- 
Grant Edwards   grant.b.edwardsYow! Well, O.K.
  at   I'll compromise with my
  gmail.comprinciples because of
   EXISTENTIAL DESPAIR!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating .exe file in Python

2015-06-15 Thread subhabrata . banerji
On Monday, June 15, 2015 at 5:12:24 PM UTC+5:30, subhabrat...@gmail.com wrote:
> Dear Group,
> 
> I am trying to learn how to create .exe file for Python. I tried to work 
> around 
> http://www.py2exe.org/index.cgi/Tutorial of Py2exe. The sample program went 
> nice.
> But if I try to make exe for larger programs with methods and classes I am 
> getting error. 
> 
> If any one of the esteemed members may kindly suggest how to work out. 
> I am using Python2.7+ on Windows 7 Professional. 
> 
> Regards,
> Subhabrata Banerjee.

Dear Madam,

Thanks. Most of it is working except the last portion as I am giving 
python setup.py py2exe

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Admin>cd\

C:\>cd Python27

C:\Python27>python NLQ3.py
Print Your Query:Java
The Tagged Value Is: [('Java', 'NNP')]
['Java']

C:\Python27>python NLQ3.py
Print Your Query:Obama is the president of USA
The Tagged Value Is: [('Obama', 'NNP'), ('is', 'VBZ'), ('the', 'DT'), ('presiden
t', 'NN'), ('of', 'IN'), ('USA', 'NNP')]
['Obama']
['president']
['USA']
['Obama', 'president']
['Obama', 'USA']
['president', 'USA']
['Obama', 'president', 'USA']

C:\Python27>python setup.py install
running install
running build
running install_egg_info
Removing C:\Python27\Lib\site-packages\UNKNOWN-0.0.0-py2.7.egg-info
Writing C:\Python27\Lib\site-packages\UNKNOWN-0.0.0-py2.7.egg-info

C:\Python27>python setup.py py2exe
running py2exe
*** searching for required modules ***
*** parsing results ***
creating python loader for extension 'scipy.optimize.minpack2' (C:\Python27\lib\
site-packages\scipy\optimize\minpack2.pyd -> scipy.optimize.minpack2.pyd)
creating python loader for extension 'numpy.core.umath' (C:\Python27\lib\site-pa
ckages\numpy\core\umath.pyd -> numpy.core.umath.pyd)
creating python loader for extension '_elementtree' (C:\Python27\DLLs\_elementtr
ee.pyd -> _elementtree.pyd)
creating python loader for extension 'matplotlib._path' (C:\Python27\lib\site-pa
ckages\matplotlib\_path.pyd -> matplotlib._path.pyd)
creating python loader for extension 'numpy.fft.fftpack_lite' (C:\Python27\lib\s
ite-packages\numpy\fft\fftpack_lite.pyd -> numpy.fft.fftpack_lite.pyd)
creating python loader for extension 'numpy.lib._compiled_base' (C:\Python27\lib
\site-packages\numpy\lib\_compiled_base.pyd -> numpy.lib._compiled_base.pyd)
creating python loader for extension 'scipy.optimize._minpack' (C:\Python27\lib\
site-packages\scipy\optimize\_minpack.pyd -> scipy.optimize._minpack.pyd)
creating python loader for extension '_ctypes' (C:\Python27\DLLs\_ctypes.pyd ->
_ctypes.pyd)
creating python loader for extension 'scipy.sparse.linalg.isolve._iterative' (C:
\Python27\lib\site-packages\scipy\sparse\linalg\isolve\_iterative.pyd -> scipy.s
parse.linalg.isolve._iterative.pyd)
creating python loader for extension 'sklearn.linear_model.sgd_fast' (C:\Python2
7\lib\site-packages\sklearn\linear_model\sgd_fast.pyd -> sklearn.linear_model.sg
d_fast.pyd)
creating python loader for extension 'scipy.stats._rank' (C:\Python27\lib\site-p
ackages\scipy\stats\_rank.pyd -> scipy.stats._rank.pyd)
creating python loader for extension 'select' (C:\Python27\DLLs\select.pyd -> se
lect.pyd)
creating python loader for extension 'scipy.sparse.csgraph._reordering' (C:\Pyth
on27\lib\site-packages\scipy\sparse\csgraph\_reordering.pyd -> scipy.sparse.csgr
aph._reordering.pyd)
creating python loader for extension 'unicodedata' (C:\Python27\DLLs\unicodedata
.pyd -> unicodedata.pyd)
creating python loader for extension 'scipy.special.specfun' (C:\Python27\lib\si
te-packages\scipy\special\specfun.pyd -> scipy.special.specfun.pyd)
creating python loader for extension 'scipy.spatial.qhull' (C:\Python27\lib\site
-packages\scipy\spatial\qhull.pyd -> scipy.spatial.qhull.pyd)
creating python loader for extension 'scipy.interpolate._ppoly' (C:\Python27\lib
\site-packages\scipy\interpolate\_ppoly.pyd -> scipy.interpolate._ppoly.pyd)
creating python loader for extension 'scipy.sparse.csgraph._tools' (C:\Python27\
lib\site-packages\scipy\sparse\csgraph\_tools.pyd -> scipy.sparse.csgraph._tools
.pyd)
creating python loader for extension 'scipy.interpolate.dfitpack' (C:\Python27\l
ib\site-packages\scipy\interpolate\dfitpack.pyd -> scipy.interpolate.dfitpack.py
d)
creating python loader for extension 'scipy.linalg._fblas' (C:\Python27\lib\site
-packages\scipy\linalg\_fblas.pyd -> scipy.linalg._fblas.pyd)
creating python loader for extension 'scipy.optimize._zeros' (C:\Python27\lib\si
te-packages\scipy\optimize\_zeros.pyd -> scipy.optimize._zeros.pyd)
creating python loader for extension 'scipy.stats.mvn' (C:\Python27\lib\site-pac
kages\scipy\stats\mvn.pyd -> scipy.stats.mvn.pyd)
creating python loader for extension 'sklearn.__check_build._check_build' (C:\Py
thon27\lib\site-packages\sklearn\__check_build\_check_build.pyd -> sklearn.__che
ck_build._check_build.pyd)
creating python loader for extension 'scipy.linalg._flinalg' (C:\Python27\lib\si
te-packa

Re: Creating .exe file in Python

2015-06-15 Thread Laura Creighton
I don't have a windows system, so my knowledge of such things is
minimal.  But looks like this person had the same problem you have,
and got some suggestions on how to fix it.

http://stackoverflow.com/questions/12127869/error-msvcp90-dll-no-such-file-or-directory-even-though-microsoft-visual-c

But your code is working fine now?  There is no point in packaging
something that doesn't run.

Laura

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


Re: Creating .exe file in Python

2015-06-15 Thread sohcahtoa82
On Monday, June 15, 2015 at 5:08:58 AM UTC-7, Mark Lawrence wrote:
> On 15/06/2015 12:42, subhabrata.bane...@gmail.com wrote:
> > Dear Group,
> >
> > I am trying to learn how to create .exe file for Python. I tried to work 
> > around
> > http://www.py2exe.org/index.cgi/Tutorial of Py2exe. The sample program went 
> > nice.
> > But if I try to make exe for larger programs with methods and classes I am 
> > getting error.
> >
> > If any one of the esteemed members may kindly suggest how to work out.
> > I am using Python2.7+ on Windows 7 Professional.
> >
> > Regards,
> > Subhabrata Banerjee.
> >
> 
> I'm awfully sorry but both my main and backup crystal balls are being 
> repaired due to overuse.  "I am getting error" is about as much use as a 
> wet fart in a thunderstorm.  So given that I never much liked guessing 
> games anyway as I'm not much good at them, how about telling us 
> precisely what error you're getting.  In that way one or more of our 
> most esteemed colleagues might be able to help.
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

"as much use as a wet fart in a thunderstorm"

I gotta remember that one.  :-D

But on topic...I really don't understand what makes people think we can 
*possibly* help them by only saying "I'm getting an error" without saying what 
the error is.

I mean, even before I ever became a programmer, I knew that if I needed help 
fixing something, I needed to give as much information as I could.  Exact error 
messages, detailed description of what I was doing, what I've done to try to 
fix it, etc.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python financial data cleaning

2015-06-15 Thread Sebastian M Cheung via Python-list
On Monday, June 15, 2015 at 11:19:48 AM UTC+1, Mark Lawrence wrote:
> On 15/06/2015 11:12, Sebastian M Cheung via Python-list wrote:
> > How to do financial data cleaning ? Say I assume a list of 1000 finance 
> > series data in myList = Open, High, Low and Close. For missing Close Price 
> > data, What is best practice to clean data in Python
> >
> 
> http://pandas.pydata.org/
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence


Hi Mark,

Below I read in DirtyData (financial data) from Excel and then find the number 
of NaN missing Closed Pricing data:

xls = pd.ExcelFile('DirtyData.xlsm')
df = xls.parse('Dirty Data', index_col=None, na_values=['NA'])
print(df.isnull().astype(int).sum()) 

So if I were to clean missing Open Price data, I could copy from previous or 
row's Close Price data, but how would I implement it? Thanks

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


Set a flag on the function or a global?

2015-06-15 Thread Steven D'Aprano
I have a function in a module which is intended to be used by importing 
that name alone, then used interactively:

from module import edir
edir(args)


edir is an enhanced version of dir, and one of the enhancements is that 
you can filter out dunder methods. I have reason to believe that people 
are split on their opinion on whether dunder methods should be shown by 
default or not: some people want to see them, others do not. Since edir 
is meant to be used interactively, I want to give people a setting to 
control whether they get dunders by default or not.

I have two ideas for this, a module-level global, or a flag set on the 
function object itself. Remember that the usual way of using this will be 
"from module import edir", there are two obvious ways to set the global:

import module
module.dunders = False

# -or-

edir.__globals__['dunders'] = False


Alternatively, I can use a flag set on the function object itself:

edir.dunders = False


Naturally you can always override the default by explicitly specifying a 
keyword argument edir(obj, dunders=flag).

Thoughts and feedback? Please vote: a module global, or a flag on the 
object? Please give reasons, and remember that the function is intended 
for interactive use.


-- 
Steven D'Aprano
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Set a flag on the function or a global?

2015-06-15 Thread Chris Angelico
On Tue, Jun 16, 2015 at 9:57 AM, Steven D'Aprano
 wrote:
> I have two ideas for this, a module-level global, or a flag set on the
> function object itself. Remember that the usual way of using this will be
> "from module import edir", there are two obvious ways to set the global:
>
> import module
> module.dunders = False
>
> # -or-
>
> edir.__globals__['dunders'] = False
>
>
> Alternatively, I can use a flag set on the function object itself:
>
> edir.dunders = False
>

For most situations, the last one is extremely surprising - attributes
on functions aren't normally meant to be changed by outside callers,
it always feels wrong (they belong to the function itself). But since
this is interactive, I'd advise going for the absolute simplest, which
this would be. Go for the function attribute IMO.

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


Re: Set a flag on the function or a global?

2015-06-15 Thread Ethan Furman

On 06/15/2015 04:57 PM, Steven D'Aprano wrote:


Thoughts and feedback? Please vote: a module global, or a flag on the
object? Please give reasons, and remember that the function is intended
for interactive use.


Function attribute.

Setting a global on the module (which I may not have, and probably didn't, 
import) for only one function is overkill.

  edir.dunders = False # or True

is simple, elegant, easier to type, and perfectly in keeping with Python's 
dynamic nature.

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Re: Set a flag on the function or a global?

2015-06-15 Thread Ben Finney
Chris Angelico  writes:

> On Tue, Jun 16, 2015 at 9:57 AM, Steven D'Aprano
>  wrote:
> > I can use a flag set on the function object itself:
> >
> > edir.dunders = False
>
> For most situations, the last one is extremely surprising - attributes
> on functions aren't normally meant to be changed by outside callers,
> it always feels wrong (they belong to the function itself).

I'm surprised by your assertion. To my mind, outside callers get simple
and direct access to the attribute, whereas the code of the function
itself does not have such easy access; unlike ‘self’ for the current
instance of a class, there's no obvious name to use for referring to the
function object within the function object's own code.

In what sense do they “belong to” the function itself *more than* to
outside callers?

-- 
 \   “It's easy to play any musical instrument: all you have to do |
  `\   is touch the right key at the right time and the instrument |
_o__)will play itself.” —Johann Sebastian Bach |
Ben Finney

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


Re: Set a flag on the function or a global?

2015-06-15 Thread Ethan Furman

On 06/15/2015 05:07 PM, Chris Angelico wrote:

On Tue, Jun 16, 2015 at 9:57 AM, Steven D'Aprano wrote:



I have two ideas for this, a module-level global, or a flag set on the
function object itself. Remember that the usual way of using this will be
"from module import edir", there are two obvious ways to set the global:

import module
module.dunders = False

# -or-

edir.__globals__['dunders'] = False


Alternatively, I can use a flag set on the function object itself:

edir.dunders = False



For most situations, the last one is extremely surprising - attributes
on functions aren't normally meant to be changed by outside callers,


I find this viewpoint surprising, since function attributes are fairly rare.


it always feels wrong (they belong to the function itself).


This seems silly -- a function is just another instance of some class.

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Re: Set a flag on the function or a global?

2015-06-15 Thread sohcahtoa82
On Monday, June 15, 2015 at 4:57:53 PM UTC-7, Steven D'Aprano wrote:
> I have a function in a module which is intended to be used by importing 
> that name alone, then used interactively:
> 
> from module import edir
> edir(args)
> 
> 
> edir is an enhanced version of dir, and one of the enhancements is that 
> you can filter out dunder methods. I have reason to believe that people 
> are split on their opinion on whether dunder methods should be shown by 
> default or not: some people want to see them, others do not. Since edir 
> is meant to be used interactively, I want to give people a setting to 
> control whether they get dunders by default or not.
> 
> I have two ideas for this, a module-level global, or a flag set on the 
> function object itself. Remember that the usual way of using this will be 
> "from module import edir", there are two obvious ways to set the global:
> 
> import module
> module.dunders = False
> 
> # -or-
> 
> edir.__globals__['dunders'] = False
> 
> 
> Alternatively, I can use a flag set on the function object itself:
> 
> edir.dunders = False
> 
> 
> Naturally you can always override the default by explicitly specifying a 
> keyword argument edir(obj, dunders=flag).
> 
> Thoughts and feedback? Please vote: a module global, or a flag on the 
> object? Please give reasons, and remember that the function is intended 
> for interactive use.
> 
> 
> -- 
> Steven D'Aprano

Using a keyword argument for the edir function is the most intuitive and easy 
to read, IMO.

Also, if two people are working on the same script, it could create problems if 
one person wants to filter them, but the other doesn't.  That would create a 
state that they would both have to monitor and keep setting back and forth, 
rather than each one just setting an argument on their calls.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Set a flag on the function or a global?

2015-06-15 Thread Ron Adam



On 06/15/2015 08:07 PM, Chris Angelico wrote:

On Tue, Jun 16, 2015 at 9:57 AM, Steven D'Aprano
  wrote:

>I have two ideas for this, a module-level global, or a flag set on the
>function object itself. Remember that the usual way of using this will be
>"from module import edir", there are two obvious ways to set the global:
>
>import module
>module.dunders = False
>
># -or-
>
>edir.__globals__['dunders'] = False
>
>
>Alternatively, I can use a flag set on the function object itself:
>
>edir.dunders = False
>

For most situations, the last one is extremely surprising - attributes
on functions aren't normally meant to be changed by outside callers,


Or inside callers either.  You can't be sure of the name and there is no self.



it always feels wrong (they belong to the function itself). But since
this is interactive, I'd advise going for the absolute simplest, which
this would be. Go for the function attribute IMO.



Another way is to make it an object with a __call__ method.

The the attribute can be accessed from both outside and inside dependably.

Cheers,
   Ron

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


Re: Set a flag on the function or a global?

2015-06-15 Thread Chris Angelico
On Tue, Jun 16, 2015 at 10:20 AM, Ben Finney  wrote:
> Chris Angelico  writes:
>
>> On Tue, Jun 16, 2015 at 9:57 AM, Steven D'Aprano
>>  wrote:
>> > I can use a flag set on the function object itself:
>> >
>> > edir.dunders = False
>>
>> For most situations, the last one is extremely surprising - attributes
>> on functions aren't normally meant to be changed by outside callers,
>> it always feels wrong (they belong to the function itself).
>
> I'm surprised by your assertion. To my mind, outside callers get simple
> and direct access to the attribute, whereas the code of the function
> itself does not have such easy access; unlike ‘self’ for the current
> instance of a class, there's no obvious name to use for referring to the
> function object within the function object's own code.
>
> In what sense do they “belong to” the function itself *more than* to
> outside callers?

Custom function attributes (as in, those not set by the interpreter
itself) are pretty rare, but I've usually seen them only being defined
by the module that created them. Setting that kind of attribute
externally, from a different module, seems odd - and undiscoverable.
But for interactive work, that should be fine.

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


Re: Set a flag on the function or a global?

2015-06-15 Thread MRAB

On 2015-06-16 01:24, sohcahto...@gmail.com wrote:

On Monday, June 15, 2015 at 4:57:53 PM UTC-7, Steven D'Aprano wrote:

I have a function in a module which is intended to be used by
importing that name alone, then used interactively:

from module import edir edir(args)


edir is an enhanced version of dir, and one of the enhancements is
that you can filter out dunder methods. I have reason to believe
that people are split on their opinion on whether dunder methods
should be shown by default or not: some people want to see them,
others do not. Since edir is meant to be used interactively, I want
to give people a setting to control whether they get dunders by
default or not.

I have two ideas for this, a module-level global, or a flag set on
the function object itself. Remember that the usual way of using
this will be "from module import edir", there are two obvious ways
to set the global:

import module module.dunders = False

# -or-

edir.__globals__['dunders'] = False


Alternatively, I can use a flag set on the function object itself:

edir.dunders = False


Naturally you can always override the default by explicitly
specifying a keyword argument edir(obj, dunders=flag).

Thoughts and feedback? Please vote: a module global, or a flag on
the object? Please give reasons, and remember that the function is
intended for interactive use.


-- Steven D'Aprano


Using a keyword argument for the edir function is the most intuitive
and easy to read, IMO.

Also, if two people are working on the same script, it could create
problems if one person wants to filter them, but the other doesn't.
That would create a state that they would both have to monitor and
keep setting back and forth, rather than each one just setting an
argument on their calls.


But it's meant to be used interactively. If they're using it in a
script, they'd most likely set the argument appropriately.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Set a flag on the function or a global?

2015-06-15 Thread Paul Rubin
Steven D'Aprano  writes:
> Thoughts and feedback? Please vote: a module global, or a flag on the 
> object? Please give reasons, and remember that the function is intended 
> for interactive use.

Both are bad.  More state to remember, ugh.  Instead have separate entry
points for filtering or not filtering the dunders.  Something like:

  edir(obj) = no dunders
  edir_(obj) = dunders.  

If you also support the keyword arg, then you could have

  edir_(obj)=functools.partial(edir,dunders=True).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Set a flag on the function or a global?

2015-06-15 Thread Ethan Furman

On 06/15/2015 05:37 PM, Paul Rubin wrote:

Steven D'Aprano  writes:

Thoughts and feedback? Please vote: a module global, or a flag on the
object? Please give reasons, and remember that the function is intended
for interactive use.


Both are bad.  More state to remember, ugh.  Instead have separate entry
points for filtering or not filtering the dunders.  Something like:

   edir(obj) = no dunders
   edir_(obj) = dunders.


`edir_` ?  What a horrible name.  I hate trailing underscores.  Too easy to 
miss.

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Re: Set a flag on the function or a global?

2015-06-15 Thread MRAB

On 2015-06-16 01:53, Ethan Furman wrote:

On 06/15/2015 05:37 PM, Paul Rubin wrote:

Steven D'Aprano  writes:

Thoughts and feedback? Please vote: a module global, or a flag on the
object? Please give reasons, and remember that the function is intended
for interactive use.


Both are bad.  More state to remember, ugh.  Instead have separate entry
points for filtering or not filtering the dunders.  Something like:

   edir(obj) = no dunders
   edir_(obj) = dunders.


`edir_` ?  What a horrible name.  I hate trailing underscores.  Too easy to 
miss.


Especially when there's also `edir`! :-)

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


Re: Set a flag on the function or a global?

2015-06-15 Thread Paul Rubin
Ethan Furman  writes:
>>edir_(obj) = dunders.
> `edir_` ?  What a horrible name.  I hate trailing underscores.  Too easy to 
> miss.

They've worked ok for me at various times.  edir_u (for unfiltered) is
another idea.
-- 
https://mail.python.org/mailman/listinfo/python-list


Struggling with os.path.join and fileinput (was 'Path, strings, and lines'

2015-06-15 Thread Malik Rumi
On Saturday, June 13, 2015 at 1:25:52 PM UTC-5, MRAB wrote:
> On 2015-06-13 05:48, Malik Rumi wrote:
> > On Friday, June 12, 2015 at 3:31:36 PM UTC-5, Ian wrote:
> >> On Fri, Jun 12, 2015 at 1:39 PM, Malik Rumi wrote:
> >> >  I am trying to find a list of strings in a directory of files. Here is 
> >> > my code:
> >> >
> >> > # -*- coding: utf-8 -*-
> >> > import os
> >> > import fileinput
> >> >
> >> > s2 = os.listdir('/home/malikarumi/Projects/P5/shortstories')
> >>
> >> Note that the filenames that will be returned here are not fully
> >> qualified: you'll just get filename.txt, not
> >> /home/.../shortstories/filename.txt.
> >>
> >
> > Yes, that is what I want.
> >
> >> > for line in lines:
> >> >  for item in fileinput.input(s2):
> >>
> >> fileinput doesn't have the context of the directory that you listed
> >> above, so it's just going to look in the current directory.
> >
> > Can you explain a little more what you mean by fileinput lacking the 
> > context of s4?
> >
> listdir returns the names of the files that are in the folder, not
> their paths.
> 
> If you give fileinput only the names of the files, it'll assume they're
> in the current folder (directory), which they (probably) aren't. You
> need to give fileinput the complete _paths_ of the files, not just
> their names.
> 
> >>
> >> >  if line in item:
> >> > with open(line + '_list', 'a+') as l:
> >> > l.append(filename(), filelineno(), line)
> >>
> >> Although it's not the problem at hand, I think you'll find that you
> >> need to qualify the filename() and filelineno() function calls with
> >> the fileinput module.
> >
> > By 'qualify', do you mean something like
> > l.append(fileinput.filename())?
> >
> >>
> >> > FileNotFoundError: [Errno 2] No such file or directory: 'THE LAND OF 
> >> > LOST TOYS~'
> >>
> >> And here you can see that it's failing to find the file because it's
> >> looking in the wrong directory. You can use the os.path.join function
> >> to add the proper directory path to the filenames that you pass to
> >> fileinput.
> >
> > I tried new code:
> >
> > # -*- coding: utf-8 -*-
> > import os
> > import fileinput
> >
> >
> os.join _returns its result.
> 
> > os.path.join('/Projects/Pipeline/4 Transforms', 
> > '/Projects/P5/shortstories/')
> > s2 = os.listdir('/Projects/P5/shortstories/')
> 
> At this point, s2 contains a list of _names_.
> 
> You pass those names to fileinput.input, but where are they? In which
> folder? It assumes they're in the current folder (directory), but
> they're not!
> 
> > for item in fileinput.input(s2):
> >   if 'penelope' in item:
> >  print(item)
> >
> > But still got the same errors even though the assignment of the path 
> > variable seems to have worked:
> >
> [snip]
> 
> Try this:
> 
>  filenames = os.listdir('/Projects/P5/shortstories/')
>  paths = [os.join('/Projects/P5/shortstories/', name) for name in names]
>  for item in fileinput.input(paths):

I have struggled with this for several hours and not made much progress. I was 
not sure if your 'names' variable was supposed to be the same as 'filenames'. 
Also, it should be 'os.path.join', not os.join. Anyway, I thought you had some 
good ideas so I worked with them but as I say I keep getting stuck at one 
particular point. Here is the current version of my code:

# -*- coding: utf-8 -*-
import os
import fileinput

path1 = os.path.join('Projects', 'P5', 'shortstories', '/')
path2 = os.path.join('Projects', 'P5')
targets = os.listdir(path1)
path3 = ((path1 + target) for target in targets)
path4 = os.path.join(path2,'list_stories')

with open(path4) as arrows:
quiver = arrows.readlines()


And here is my error message:

In [112]: %run algo_h1.py
---
FileNotFoundError Traceback (most recent call last)
/home/malikarumi/Projects/algo_h1.py in ()
  9 path4 = os.path.join(path2,'list_stories')
 10 
---> 11 with open(path4) as arrows:
 12 quiver = arrows.readlines()
 13 for arrow in quiver:

FileNotFoundError: [Errno 2] No such file or directory: 
'Projects/P5/list_stories'

I have tried many different ways but can't get python to find list_stories, 
which is the list of story names I want to find in the texts contained in 
path3. When I got a lesser version of this to work I had all relevant files in 
the same directory. This is a more realistic situation, but I can't make it 
work. Suggestions?

On a slightly different but closely related issue:

As I continued to work on this on my own, I learned that I could use the class, 
fileinput.FileInput, instead of fileinput.input. The supposed advantage is that 
there can be many simultaneous instances with the class. 
http://stackoverflow.com/questions/21443601/runtimeerror-input-already-active-file-loop.
 I tried this with a very basic version of my code, one that had worked with 
fileinput.input, and FileInput

Re: Struggling with os.path.join and fileinput (was 'Path, strings, and lines'

2015-06-15 Thread Ian Kelly
On Mon, Jun 15, 2015 at 8:00 PM, Malik Rumi  wrote:
> I have struggled with this for several hours and not made much progress. I 
> was not sure if your 'names' variable was supposed to be the same as 
> 'filenames'. Also, it should be 'os.path.join', not os.join. Anyway, I 
> thought you had some good ideas so I worked with them but as I say I keep 
> getting stuck at one particular point. Here is the current version of my code:
>
> # -*- coding: utf-8 -*-
> import os
> import fileinput
>
> path1 = os.path.join('Projects', 'P5', 'shortstories', '/')

You don't need to join the trailing slash on. Also, you don't really
need os.path.join here, unless you're trying to be compatible with
systems that don't allow / as a path separator, which is probably not
worth worrying about, so you could leave out the join call here and
just write '/Projects/P5/shortstories'.

> path2 = os.path.join('Projects', 'P5')

Ditto.

> targets = os.listdir(path1)
> path3 = ((path1 + target) for target in targets)

This however is not just a constant so you *should* use os.path.join
rather than concatenation.

> path4 = os.path.join(path2,'list_stories')
>
> with open(path4) as arrows:
> quiver = arrows.readlines()
> 
>
> And here is my error message:
>
> In [112]: %run algo_h1.py
> ---
> FileNotFoundError Traceback (most recent call last)
> /home/malikarumi/Projects/algo_h1.py in ()
>   9 path4 = os.path.join(path2,'list_stories')
>  10
> ---> 11 with open(path4) as arrows:
>  12 quiver = arrows.readlines()
>  13 for arrow in quiver:
>
> FileNotFoundError: [Errno 2] No such file or directory: 
> 'Projects/P5/list_stories'

Before you were using '/Projects/P5/list_stories'. Now as the error
message shows you are using 'Projects/P5/list_stories', which is not
the same thing. The former is an absolute path and the latter is
relative to the current directory. You can fix that by adding the
leading / to the os.path.join call above, or just include it in the
string constant as I suggested.

> As I continued to work on this on my own, I learned that I could use the 
> class, fileinput.FileInput, instead of fileinput.input. The supposed 
> advantage is that there can be many simultaneous instances with the class. 
> http://stackoverflow.com/questions/21443601/runtimeerror-input-already-active-file-loop.
>  I tried this with a very basic version of my code, one that had worked with 
> fileinput.input, and FileInput worked just as well. Then I wanted to try a 
> 'with' statement, because that would take care of closing the file objects 
> for me. I took my formulation directly from the docs, 
> https://docs.python.org/3.4/library/fileinput.html#fileinput.FileInput, but 
> got a NameError:
>
> In [81]: %run algo_g3.py
> ---
> NameError Traceback (most recent call last)
> /home/malikarumi/Projects/P5/shortstories/algo_g3.py in ()
>   4 ss = os.listdir()
>   5
> > 6 with FileInput(files = ss) as input:
>   7 if 'Penelope' in input:
>   8 print(input)
>
> NameError: name 'FileInput' is not defined
>
> Well, I am pretty much stumped by that. If it isn't right in the docs, what 
> hope do I have? What am I missing here? Why did I get this error?

How did you import it? If you just did 'import fileinput' then the
name that you imported is just the name of the module, fileinput, so
you would have to write 'fileinput.FileInput', not just 'FileInput'.
If OTOH you had used 'from fileinput import FileInput', then the name
you would have imported would be the name of the class, and in that
case the above should be correct.

> I decided to try tinkering with the parens
>
> with FileInput(files = (ss)) as input:
>
> But that got me the same result
>
> NameError: name 'FileInput' is not defined

As the error says, the issue is that the name 'FileInput' is not
defined, not anything to do with the arguments that you're passing to
it. As it happens, the change that you made was a no-op. The parens
only affect grouping, and the grouping is the same as before.

> Then I changed how FileInput was called:
>
> with fileinput.FileInput(ss) as input:
>
> This time I got nothing. Zip. Zero:

Because it worked this time, meaning that it successfully opened the
files, but then it failed to find the string that you were searching
for. Your "if 'Penelope' in input" conditional will iterate over each
line in input, and if it finds a line that is exactly 'Penelope'
without any trailing newline, then it will print the line. You
probably wanted this instead:

with fileinput.FileInput(ss) as input:
for line in input:
if 'Penelope' in line:
print(line)

> Then I ran a different function
>
> In [85]: fileinput.filename()
>
> and got
>
> RuntimeError: no active input()
>
> Which means the file object

Re: Struggling with os.path.join and fileinput (was 'Path, strings, and lines'

2015-06-15 Thread MRAB

On 2015-06-16 03:00, Malik Rumi wrote:

On Saturday, June 13, 2015 at 1:25:52 PM UTC-5, MRAB wrote:

On 2015-06-13 05:48, Malik Rumi wrote:
> On Friday, June 12, 2015 at 3:31:36 PM UTC-5, Ian wrote:
>> On Fri, Jun 12, 2015 at 1:39 PM, Malik Rumi wrote:
>> >  I am trying to find a list of strings in a directory of files. Here is my 
code:
>> >
>> > # -*- coding: utf-8 -*-
>> > import os
>> > import fileinput
>> >
>> > s2 = os.listdir('/home/malikarumi/Projects/P5/shortstories')
>>
>> Note that the filenames that will be returned here are not fully
>> qualified: you'll just get filename.txt, not
>> /home/.../shortstories/filename.txt.
>>
>
> Yes, that is what I want.
>
>> > for line in lines:
>> >  for item in fileinput.input(s2):
>>
>> fileinput doesn't have the context of the directory that you listed
>> above, so it's just going to look in the current directory.
>
> Can you explain a little more what you mean by fileinput lacking the context 
of s4?
>
listdir returns the names of the files that are in the folder, not
their paths.

If you give fileinput only the names of the files, it'll assume they're
in the current folder (directory), which they (probably) aren't. You
need to give fileinput the complete _paths_ of the files, not just
their names.

>>
>> >  if line in item:
>> > with open(line + '_list', 'a+') as l:
>> > l.append(filename(), filelineno(), line)
>>
>> Although it's not the problem at hand, I think you'll find that you
>> need to qualify the filename() and filelineno() function calls with
>> the fileinput module.
>
> By 'qualify', do you mean something like
> l.append(fileinput.filename())?
>
>>
>> > FileNotFoundError: [Errno 2] No such file or directory: 'THE LAND OF LOST 
TOYS~'
>>
>> And here you can see that it's failing to find the file because it's
>> looking in the wrong directory. You can use the os.path.join function
>> to add the proper directory path to the filenames that you pass to
>> fileinput.
>
> I tried new code:
>
> # -*- coding: utf-8 -*-
> import os
> import fileinput
>
>
os.join _returns its result.

> os.path.join('/Projects/Pipeline/4 Transforms', '/Projects/P5/shortstories/')
> s2 = os.listdir('/Projects/P5/shortstories/')

At this point, s2 contains a list of _names_.

You pass those names to fileinput.input, but where are they? In which
folder? It assumes they're in the current folder (directory), but
they're not!

> for item in fileinput.input(s2):
>   if 'penelope' in item:
>  print(item)
>
> But still got the same errors even though the assignment of the path variable 
seems to have worked:
>
[snip]

Try this:

 filenames = os.listdir('/Projects/P5/shortstories/')
 paths = [os.join('/Projects/P5/shortstories/', name) for name in names]
 for item in fileinput.input(paths):


I have struggled with this for several hours and not made much progress. I was 
not sure if your 'names' variable was supposed to be the same as 'filenames'. 
Also, it should be 'os.path.join', not os.join.


Yes on both points. Apologies.

Anyway, I thought you had some good ideas so I worked with them but as I 
say I keep getting stuck at one particular point. Here is the current 
version of my code:


# -*- coding: utf-8 -*-
import os
import fileinput

path1 = os.path.join('Projects', 'P5', 'shortstories', '/')
path2 = os.path.join('Projects', 'P5')
targets = os.listdir(path1)
path3 = ((path1 + target) for target in targets)
path4 = os.path.join(path2,'list_stories')

with open(path4) as arrows:
 quiver = arrows.readlines()


And here is my error message:

In [112]: %run algo_h1.py
---
FileNotFoundError Traceback (most recent call last)
/home/malikarumi/Projects/algo_h1.py in ()
   9 path4 = os.path.join(path2,'list_stories')
  10
---> 11 with open(path4) as arrows:
  12 quiver = arrows.readlines()
  13 for arrow in quiver:

FileNotFoundError: [Errno 2] No such file or directory: 
'Projects/P5/list_stories'


So it can't find 'Projects/P5/list_stories'. That's a relative path (it
doesn't begin at the root ('/')), so it starts look in the current
directory.

Should it be '/home/malikarumi/Projects/P5/list_stories'?

If that's the correct full path, but '/home/malikarumi' isn't the
current directory, then it won't find it.


I have tried many different ways but can't get python to find list_stories, 
which is the list of story names I want to find in the texts contained in 
path3. When I got a lesser version of this to work I had all relevant files in 
the same directory. This is a more realistic situation, but I can't make it 
work. Suggestions?

On a slightly different but closely related issue:

As I continued to work on this on my own, I learned that I could use the class, 
fileinput.FileInput, instead of fileinput.input. The supposed advantage is that 
there can be many simultaneous instances with the

Re: Trying to configure Apache and Python 2.7 on Red Hat I get 403 Forbidden

2015-06-15 Thread Néstor Boscán
Tried it and I keep having the same error. Isn't there a log file where I
can check what is causing this?

Regards,

Néstor

On Sat, Jun 13, 2015 at 8:47 AM, zhou weitao  wrote:

> selinux is causing this, I guess. Please try run *setenforce 1* to bypass
> it firstly. If it works then google the related configuration.
>
>
> from ex-redhatter
>
> 2015-06-12 20:51 GMT+08:00 Néstor Boscán :
>
>> Hi
>>
>> I've been trying to configure Apache and Python 2.7 on Red Hat. I've
>> tried the different configurations i've seen on the web, I've given chmod
>> -R 777 tu my python code but I still get 403 Forbidden and I don't get any
>> errors.
>>
>> Regards,
>>
>> Néstor
>>
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Set a flag on the function or a global?

2015-06-15 Thread Mark Lawrence

On 16/06/2015 00:57, Steven D'Aprano wrote:

I have a function in a module which is intended to be used by importing
that name alone, then used interactively:

 from module import edir
 edir(args)


edir is an enhanced version of dir, and one of the enhancements is that
you can filter out dunder methods. I have reason to believe that people
are split on their opinion on whether dunder methods should be shown by
default or not: some people want to see them, others do not. Since edir
is meant to be used interactively, I want to give people a setting to
control whether they get dunders by default or not.

I have two ideas for this, a module-level global, or a flag set on the
function object itself. Remember that the usual way of using this will be
"from module import edir", there are two obvious ways to set the global:

import module
module.dunders = False

# -or-

edir.__globals__['dunders'] = False


Alternatively, I can use a flag set on the function object itself:

edir.dunders = False


Naturally you can always override the default by explicitly specifying a
keyword argument edir(obj, dunders=flag).

Thoughts and feedback? Please vote: a module global, or a flag on the
object? Please give reasons, and remember that the function is intended
for interactive use.




For interactive use I'd be perfectly happy with just the keyword 
argument.  Why bother toggling something when I can explicitly set it in 
the call each and every time?  If I have to choose it's a flag on the 
object, just no competition.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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