Re: How can I get/save Pandas DataFrame help content?

2015-12-16 Thread Steven D'Aprano
On Thursday 17 December 2015 13:48, Robert wrote:

> Hi,
> 
> When I use Enthought/Canopy, help(DataFrame) has so much content that it
> exceeds the display buffer, i.e. its head is cut off as I go up to see it.


Step 1: report this as a bug to Enthought and/or the Python bug tracker. 
help(DataFrame) should automatically choose a pager such as `less` on Linux 
or equivalent (`more` I think?) on Windows.

Step 2: in the meantime, while you wait for Enthought to fix this, you can 
try any of these:

(a) open the regular Python interactive interpreter (do you need help with 
that?);  once you have the >>> prompt, import the module that DataFrame 
comes from, then run help:


import whatever
help(whatever.DataFrame)


The regular interactive interpreter ought to automatically pick a pager. If 
it doesn't, that's a bug.


(b) At the shell prompt (most likely a $ or # prompt) run:

pydoc whatever.DataFrame

if necessarily piping it to the pager or file of your choice using your 
shell's normal redirection syntax, e.g.:

pydoc whatever.DataFrame | less


(Remember, this is at the shell $ prompt, not the Python >>> prompt.)


(c) If your OS can't find "pydoc", try this instead:

python -m pydoc whatever.DataFrame





-- 
Steve

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


Re: cannot open file with non-ASCII filename

2015-12-16 Thread eryk sun
On Tue, Dec 15, 2015 at 11:04 AM, Ulli Horlacher
 wrote:
>
> Ehhh... I started Python programming some weeks ago and I know nearly
> nothing about Windows. I am a UNIX and VMS guy :-)

You should feel right at home, then. The Windows NT kernel was
designed and implemented by a team of former DEC engineers led by
David Cutler, who was one of the principle architects of VMS. There's
an old joke that W[indows] NT is VMS + 1. Actually, you'd probably
only notice a slight resemblance if you were coding a driver [1].
Microsoft discourages using the native NT API in user mode.

Windows client DLLs such as kernel32.dll usually implement an API
function in one of three ways, or in combination:

using the native runtime library and loader functions
(Rtl* & Ldr* in ntdll.dll)

calling system services such as

Nt* public APIs (ntdll.dll => ntoskrnl.exe)
NtUser* & NtGdi* private APIs
(user32.dll, gdi32.dll => win32k.sys)

using a local procedure call (via ALPC or a driver) to a
subsystem process such as

csrss.exe- Windows client/server runtime
conhost.exe  - console host
services.exe - service control manager
lsass.exe- local security authority
smss.exe - session manager

But this is all an implementation detail. The API could be implemented
in a totally different way in a totally different environment, such as
running WINE on Linux.

[1]: http://windowsitpro.com/windows-client/windows-nt-and-vms-rest-story
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How can I get/save Pandas DataFrame help content?

2015-12-16 Thread Chris Angelico
On Thu, Dec 17, 2015 at 2:20 PM, Robert  wrote:
> On Wednesday, December 16, 2015 at 9:56:23 PM UTC-5, Chris Angelico wrote:
>> On Thu, Dec 17, 2015 at 1:48 PM, Robert  wrote:
>> > Hi,
>> >
>> > When I use Enthought/Canopy, help(DataFrame) has so much content that it
>> > exceeds the display buffer, i.e. its head is cut off as I go up to see it.
>> > I would like to know whether there is a way similar to Linux redirection to
>> > save the help DataFrame content to a file?
>>
>> If you use command-line Python (by just running 'python' or 'python3'
>> in your shell), you should be able to use help() with a More pager.
>>
>> ChrisA
>
> Thanks for this useful idea.
> I have tried with:
>
> help(DataFrame) | more
> NameError Traceback (most recent call last)
>  in ()
> > 1 help(DataFrame) | more
>
> NameError: name 'more' is not defined
> 
> It is possible I misunderstand your method. Could you give me a little more
> description on it?

Sorry for the confusion. You don't need to explicitly request the
pager; the default interpreter configuration should include that.

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


Re: How can I get/save Pandas DataFrame help content?

2015-12-16 Thread Robert
On Wednesday, December 16, 2015 at 9:56:23 PM UTC-5, Chris Angelico wrote:
> On Thu, Dec 17, 2015 at 1:48 PM, Robert  wrote:
> > Hi,
> >
> > When I use Enthought/Canopy, help(DataFrame) has so much content that it
> > exceeds the display buffer, i.e. its head is cut off as I go up to see it.
> > I would like to know whether there is a way similar to Linux redirection to
> > save the help DataFrame content to a file?
> 
> If you use command-line Python (by just running 'python' or 'python3'
> in your shell), you should be able to use help() with a More pager.
> 
> ChrisA

Thanks for this useful idea.
I have tried with: 

help(DataFrame) | more
NameError Traceback (most recent call last)
 in ()
> 1 help(DataFrame) | more

NameError: name 'more' is not defined 

It is possible I misunderstand your method. Could you give me a little more
description on it?

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


Re: How can I get/save Pandas DataFrame help content?

2015-12-16 Thread Chris Angelico
On Thu, Dec 17, 2015 at 1:48 PM, Robert  wrote:
> Hi,
>
> When I use Enthought/Canopy, help(DataFrame) has so much content that it
> exceeds the display buffer, i.e. its head is cut off as I go up to see it.
> I would like to know whether there is a way similar to Linux redirection to
> save the help DataFrame content to a file?

If you use command-line Python (by just running 'python' or 'python3'
in your shell), you should be able to use help() with a More pager.

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


How can I get/save Pandas DataFrame help content?

2015-12-16 Thread Robert
Hi,

When I use Enthought/Canopy, help(DataFrame) has so much content that it 
exceeds the display buffer, i.e. its head is cut off as I go up to see it.
I would like to know whether there is a way similar to Linux redirection to
save the help DataFrame content to a file?

I have search on-line Pandas DataFrame web page. Surprisingly, it has much
less content than help(DataFrame) command.

If there is no way to save the content to a file, do you know where I can get
the full help DataFrame content on a web page?


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


Re: Help on error " ValueError: For numerical factors, num_columns must be an int "

2015-12-16 Thread Robert
On Wednesday, December 16, 2015 at 8:57:30 PM UTC-5, Josef Pktd wrote:
> On Wednesday, December 16, 2015 at 9:50:35 AM UTC-5, Robert wrote:
> > On Wednesday, December 16, 2015 at 6:34:21 AM UTC-5, Mark Lawrence wrote:
> > > On 16/12/2015 10:44, Robert wrote:
> > > > Hi,
> > > >
> > > > When I run the following code, there is an error:
> > > >
> > > > ValueError: For numerical factors, num_columns must be an int
> > > >
> > > >
> > > > 
> > > > import numpy as np
> > > > import pandas as pd
> > > > from patsy import dmatrices
> > > > from sklearn.linear_model import LogisticRegression
> > > >
> > > > X = [0.5,0.75,1.0,1.25,1.5,1.75,1.75,2.0,2.25,2.5,2.75,3.0,3.25,
> > > > 3.5,4.0,4.25,4.5,4.75,5.0,5.5]
> > > > y = [0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,1,1,1,1,1]
> > > >
> > > > zipped = list(zip(X,y))
> > > > df = pd.DataFrame(zipped,columns = ['study_hrs','p_or_f'])
> > > >
> > > > y, X = dmatrices('p_or_f ~ study_hrs', df, return_type="dataframe")
> > > > ===
> > > >
> > > > I have check 'df' is this type:
> > > > =
> > > > type(df)
> > > > Out[25]: pandas.core.frame.DataFrame
> > > > =
> > > >
> > > > I cannot figure out where the problem is. Can you help me?
> > > > Thanks.
> > > >
> > > > Error message:
> > > > ..
> > > >
> > > >
> > > > ---
> > > > ValueErrorTraceback (most recent call 
> > > > last)
> > > > C:\Users\rj\pyprj\stackoverflow_logisticregression0.py in ()
> > > >   17 df = pd.DataFrame(zipped,columns = ['study_hrs','p_or_f'])
> > > >   18
> > > > ---> 19 y, X = dmatrices('p_or_f ~ study_hrs', df, 
> > > > return_type="dataframe")
> > > >   20
> > > >   21 y = np.ravel(y)
> > > >
> > > > C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\highlevel.pyc
> > > >  in dmatrices(formula_like, data, eval_env, NA_action, return_type)
> > > >  295 eval_env = EvalEnvironment.capture(eval_env, reference=1)
> > > >  296 (lhs, rhs) = _do_highlevel_design(formula_like, data, 
> > > > eval_env,
> > > > --> 297   NA_action, return_type)
> > > >  298 if lhs.shape[1] == 0:
> > > >  299 raise PatsyError("model is missing required outcome 
> > > > variables")
> > > >
> > > > C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\highlevel.pyc
> > > >  in _do_highlevel_design(formula_like, data, eval_env, NA_action, 
> > > > return_type)
> > > >  150 return iter([data])
> > > >  151 design_infos = _try_incr_builders(formula_like, 
> > > > data_iter_maker, eval_env,
> > > > --> 152   NA_action)
> > > >  153 if design_infos is not None:
> > > >  154 return build_design_matrices(design_infos, data,
> > > >
> > > > C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\highlevel.pyc
> > > >  in _try_incr_builders(formula_like, data_iter_maker, eval_env, 
> > > > NA_action)
> > > >   55   data_iter_maker,
> > > >   56   eval_env,
> > > > ---> 57   NA_action)
> > > >   58 else:
> > > >   59 return None
> > > >
> > > > C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\build.pyc
> > > >  in design_matrix_builders(termlists, data_iter_maker, eval_env, 
> > > > NA_action)
> > > >  704 factor_states[factor],
> > > >  705 
> > > > num_columns=num_column_counts[factor],
> > > > --> 706 categories=None)
> > > >  707 else:
> > > >  708 assert factor in cat_levels_contrasts
> > > >
> > > > C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\design_info.pyc
> > > >  in __init__(self, factor, type, state, num_columns, categories)
> > > >   86 if self.type == "numerical":
> > > >   87 if not isinstance(num_columns, int):
> > > > ---> 88 raise ValueError("For numerical factors, 
> > > > num_columns "
> > > >   89  "must be an int")
> > > >   90 if categories is not None:
> > > >
> > > > ValueError: For numerical factors, num_columns must be an int
> > > >
> > > 
> > > Slap the ValueError into a search engine and the first hit is 
> > > https://groups.google.com/forum/#!topic/pystatsmodels/KcSzNqDxv-Q
> 
> This was fixed in patsy 0.4.1 as discussed in this statsmodels thread.
> You need to upgrade patsy from 0.4.0.
> 
> AFAIR, the type checking was too strict and broke with recent numpy versions.
> 
> Josef
> 
> 
> > > 
> > > -- 
> > > My fellow Pythonistas, ask not what our language can do for you, ask
> > > what you can do for our language.
> > > 
> > > Mark Lawrenc

Re: Help on error " ValueError: For numerical factors, num_columns must be an int "

2015-12-16 Thread Josef Pktd
On Wednesday, December 16, 2015 at 9:50:35 AM UTC-5, Robert wrote:
> On Wednesday, December 16, 2015 at 6:34:21 AM UTC-5, Mark Lawrence wrote:
> > On 16/12/2015 10:44, Robert wrote:
> > > Hi,
> > >
> > > When I run the following code, there is an error:
> > >
> > > ValueError: For numerical factors, num_columns must be an int
> > >
> > >
> > > 
> > > import numpy as np
> > > import pandas as pd
> > > from patsy import dmatrices
> > > from sklearn.linear_model import LogisticRegression
> > >
> > > X = [0.5,0.75,1.0,1.25,1.5,1.75,1.75,2.0,2.25,2.5,2.75,3.0,3.25,
> > > 3.5,4.0,4.25,4.5,4.75,5.0,5.5]
> > > y = [0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,1,1,1,1,1]
> > >
> > > zipped = list(zip(X,y))
> > > df = pd.DataFrame(zipped,columns = ['study_hrs','p_or_f'])
> > >
> > > y, X = dmatrices('p_or_f ~ study_hrs', df, return_type="dataframe")
> > > ===
> > >
> > > I have check 'df' is this type:
> > > =
> > > type(df)
> > > Out[25]: pandas.core.frame.DataFrame
> > > =
> > >
> > > I cannot figure out where the problem is. Can you help me?
> > > Thanks.
> > >
> > > Error message:
> > > ..
> > >
> > >
> > > ---
> > > ValueErrorTraceback (most recent call 
> > > last)
> > > C:\Users\rj\pyprj\stackoverflow_logisticregression0.py in ()
> > >   17 df = pd.DataFrame(zipped,columns = ['study_hrs','p_or_f'])
> > >   18
> > > ---> 19 y, X = dmatrices('p_or_f ~ study_hrs', df, 
> > > return_type="dataframe")
> > >   20
> > >   21 y = np.ravel(y)
> > >
> > > C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\highlevel.pyc
> > >  in dmatrices(formula_like, data, eval_env, NA_action, return_type)
> > >  295 eval_env = EvalEnvironment.capture(eval_env, reference=1)
> > >  296 (lhs, rhs) = _do_highlevel_design(formula_like, data, 
> > > eval_env,
> > > --> 297   NA_action, return_type)
> > >  298 if lhs.shape[1] == 0:
> > >  299 raise PatsyError("model is missing required outcome 
> > > variables")
> > >
> > > C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\highlevel.pyc
> > >  in _do_highlevel_design(formula_like, data, eval_env, NA_action, 
> > > return_type)
> > >  150 return iter([data])
> > >  151 design_infos = _try_incr_builders(formula_like, 
> > > data_iter_maker, eval_env,
> > > --> 152   NA_action)
> > >  153 if design_infos is not None:
> > >  154 return build_design_matrices(design_infos, data,
> > >
> > > C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\highlevel.pyc
> > >  in _try_incr_builders(formula_like, data_iter_maker, eval_env, NA_action)
> > >   55   data_iter_maker,
> > >   56   eval_env,
> > > ---> 57   NA_action)
> > >   58 else:
> > >   59 return None
> > >
> > > C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\build.pyc
> > >  in design_matrix_builders(termlists, data_iter_maker, eval_env, 
> > > NA_action)
> > >  704 factor_states[factor],
> > >  705 
> > > num_columns=num_column_counts[factor],
> > > --> 706 categories=None)
> > >  707 else:
> > >  708 assert factor in cat_levels_contrasts
> > >
> > > C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\design_info.pyc
> > >  in __init__(self, factor, type, state, num_columns, categories)
> > >   86 if self.type == "numerical":
> > >   87 if not isinstance(num_columns, int):
> > > ---> 88 raise ValueError("For numerical factors, 
> > > num_columns "
> > >   89  "must be an int")
> > >   90 if categories is not None:
> > >
> > > ValueError: For numerical factors, num_columns must be an int
> > >
> > 
> > Slap the ValueError into a search engine and the first hit is 
> > https://groups.google.com/forum/#!topic/pystatsmodels/KcSzNqDxv-Q

This was fixed in patsy 0.4.1 as discussed in this statsmodels thread.
You need to upgrade patsy from 0.4.0.

AFAIR, the type checking was too strict and broke with recent numpy versions.

Josef


> > 
> > -- 
> > My fellow Pythonistas, ask not what our language can do for you, ask
> > what you can do for our language.
> > 
> > Mark Lawrence
> 
> Hi,
> I don't see a solution to my problem. I find the following demo code from 
> 
> https://patsy.readthedocs.org/en/v0.1.0/API-reference.html#patsy.dmatrix
> 
> It doesn't work either on the Canopy. Does it work on your computer?
> Thanks,
> 
> /
> demo_data("a", "x", nlevels=3)
> Out[134]: 

Re: Why my image is in bad quality ?

2015-12-16 Thread Nobody
On Wed, 16 Dec 2015 06:04:37 -0800, fsn761304 wrote:

> pixbufObj = Gdk.pixbuf_get_from_window(window, x, y, width, height) ...
> image = Image.frombuffer("RGB", (width, height),
>  pixbufObj.get_pixels(), 'raw', 'RGB', 0, 1)

The second-to-last argument should probably be Gdk.pixbuf_get_rowstride()
rather than 0.

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


Re: How does one distribute Tkinter or Qt GUI apps Developed in Python

2015-12-16 Thread Denis Akhiyarov
On Wednesday, December 16, 2015 at 6:45:50 PM UTC-6, Rick Johnson wrote:
> On Wednesday, December 16, 2015 at 6:03:55 PM UTC-6, Bruce Whealton wrote:
> 
> > Surely, one is going to want to create GUI apps for users
> > that are not Python Developers. I would not think to ask
> > someone to install Python on their system and make sure it
> > is added to the path. Maybe it is not so hard for the non-
> > technical, average users.
> > 
> > I would want to package in some way so that when launched,
> > it installs whatever is needed on the end user's computer.
> > How is this done? Are there common practices for this?
> 
> 
> Your assumptions are correct! In fact, in a language that was "supposedly" 
> designed to be an "applications language" (eat your heart out D'Aprano!!!), 
> one would think that distributing apps would not only be obvious, but also 
> intuitive!
> 
>  ALAS, THE CRUEL REALITIES OF INTERPRETED LANGUAGES SLAPS YOU IN THE PASTEY 
> WHITE FACE! 
> 
> Unlike a true "applications language", like say, um, *JAVA*, one cannot 
> simply compile an executable and distribute it in a teeny tiny binary form, 
> no, with Python, the end user must either (1) have Python on his machine 
> already, (2) download Python, or (3) you must package a Python interpreter 
> along with your script (and dependencies) -- which will end up being a very 
> large file just to run (what is in most cases) a very small script. 
> 
>  BOO-HISS!
> 
> But the good news is that, Python ships on many machines already. But of 
> course, you're seeking more consistency in your distribution QA than the 
> "wild guess" and the fickle nature of "lady luck". 
> 
> Many 3rd party libraries exist to solve your distribution issue. Google 
> probably knows about all (or at least most) of them.


if you did not notice Java/.NET ship with runtime VMs as well.
Even C/C++ have some requirements depending on the platform.
We should all switch to assembly to avoid any dependencies and port our code to 
each platform without hesitation.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How does one distribute Tkinter or Qt GUI apps Developed in Python

2015-12-16 Thread Ben Finney
Bruce Whealton  writes:

> What seems to be blatantly missing is how this would be distributed.

Distributing programs so that recipients can run them is an ongoing
problem.

Operating systems arenecessarily involved, and since not every recipient
uses the exact same configuration of the exact same version of the exact
same operating system, the means of getting your program installed and
working on their computer will differn significantly.

> In the first mentioned tutorial from Lynda.com the Tkinter app was
> related to a web page. However, the browser cannot run Python Bytecode
> or Python Scripts.

Web applications are attractive for developers in large part because web
standards are hard-won oases of compatibility across different operating
systems.

It is no accident that operating system vendors (Microsoft, Apple,
Google, etc.) keep trying to carve out attractive incompatible features
and areas of their system, to ensure some applications using those
non-standard features will only run smoothly on the operating system
controlled by that vendor.

> Surely, one is going to want to create GUI apps for users that are not
> Python Developers.

Indeed, and toolkits like Tkinter make this refreshingly easy to do in a
way that works across all mainstream operating systems today.

What is not standardised is installation of software for end users.

> I would want to package in some way so that when launched, it installs
> whatever is needed on the end user's computer. How is this done? 

This is the “bootstrap” problem: a Python program is only useful once
there is a Python interpreter installed and working on the recipient's
system. You still need to get the appropriate version of Python
installed on that recipient's operating system.

You'll need to know your target audience, make decisions about the set
of operating systems you want to support, and build a package for each
one.

> Are there common practices for this?

Common to all mainstream operating systems? No, installation of software
is one major area that makes operating systems incompatible.


For GNU+Linux systems: Up-to-date Python is easily installed as a
dependency of your package. Target the version(s) of Python you know
your recipients will have, and declare a dependency in the operating
system package you make.

For OS X: There is an old, minimal Python installation, which is
probably too old for you to target. I am not aware of a good dependency
resolution system; you'll need to get the latest stable Python onto the
recipient's system with their help.

For iOS: I'm not aware of a good way to install Python programs on iOS.

For Android: There is a decent dependency system, but again I'm not
aware of a good standard way to have a Python program install onto
Android.

For MS Windows: There is definitely no good dependency resolution system
for you to use. You'll need to bundle a Python interpreter with your
program as a single installable file. This makes your program much
larger and redundant with any other such program on the system; this is
what Microsoft has doomed developers to work with.

-- 
 \  “If we have to give up either religion or education, we should |
  `\  give up education.” —William Jennings Bryan, 1923-01 |
_o__)  |
Ben Finney

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


asyncio for UNIX socket

2015-12-16 Thread Pavlos Parissis
Hi,
I am trying to write UNIX socket client which sends 1 cmd
and saves the received data to a file.
Based on what I found on documentation I came up with::

import asyncio
class UnixProtocol(asyncio.Protocol):
def __init__(self, loop):
self.cmd = 'show stat\n'
self.loop = loop
self.data = []

def connection_made(self, transport):
transport.write(self.cmd.encode())
print('Data sent: {!r}'.format(self.message))

def data_received(self, data):
print('Data received: {!r}'.format(data))
self.data.append(data.decode())

def connection_lost(self, exc):
print('The server closed the connection')
print('Stop the event loop')
if self.data:
with open('/tmp/somedata', 'w') as fp:
fp.writelines(self.data)
self.loop.stop()

loop = asyncio.get_event_loop()
s_file = '/run/haproxy/admin1.sock'
coro = loop.create_unix_connection(lambda: UnixProtocol(loop), s_file)
loop.run_until_complete(coro)
loop.run_forever()
loop.close()

I am not sure if the above is the proper way to do the job.
Am I doing the right thing to write the data to the file when peer
closes the connection?

Thanks,
Pavlos



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


Re: How does one distribute Tkinter or Qt GUI apps Developed in Python

2015-12-16 Thread Rick Johnson
On Wednesday, December 16, 2015 at 6:03:55 PM UTC-6, Bruce Whealton wrote:

> Surely, one is going to want to create GUI apps for users
> that are not Python Developers. I would not think to ask
> someone to install Python on their system and make sure it
> is added to the path. Maybe it is not so hard for the non-
> technical, average users.
> 
> I would want to package in some way so that when launched,
> it installs whatever is needed on the end user's computer.
> How is this done? Are there common practices for this?


Your assumptions are correct! In fact, in a language that was "supposedly" 
designed to be an "applications language" (eat your heart out D'Aprano!!!), one 
would think that distributing apps would not only be obvious, but also 
intuitive!

 ALAS, THE CRUEL REALITIES OF INTERPRETED LANGUAGES SLAPS YOU IN THE PASTEY 
WHITE FACE! 

Unlike a true "applications language", like say, um, *JAVA*, one cannot simply 
compile an executable and distribute it in a teeny tiny binary form, no, with 
Python, the end user must either (1) have Python on his machine already, (2) 
download Python, or (3) you must package a Python interpreter along with your 
script (and dependencies) -- which will end up being a very large file just to 
run (what is in most cases) a very small script. 

 BOO-HISS!

But the good news is that, Python ships on many machines already. But of 
course, you're seeking more consistency in your distribution QA than the "wild 
guess" and the fickle nature of "lady luck". 

Many 3rd party libraries exist to solve your distribution issue. Google 
probably knows about all (or at least most) of them.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tk alternative to askopenfilename and askdirectory?

2015-12-16 Thread Rick Johnson
On Wednesday, December 16, 2015 at 7:19:25 AM UTC-6, Ulli Horlacher wrote:
> Is there an alternative to Tk's askopenfilename() and askdirectory()?
> 
> I want to select a files and directories within one widget, but
> askopenfilename() let me only select files and askdirectory() let me only
> select directories.

Oh i understand. What you opine for is something like: askOpenFileOrDir() --  
which displays a dialog from which a file or directory can be selected by the 
user. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How does one distribute Tkinter or Qt GUI apps Developed in Python

2015-12-16 Thread Christian Gollwitzer

Am 17.12.15 um 01:03 schrieb Bruce Whealton:

I watched one training video that discussed Python and Tkinter. Like many 
similar tutorials from online training sites, I was left scratching my head.

What seems to be blatantly missing is how this would be distributed. In the 
first mentioned tutorial from Lynda.com the Tkinter app was related to a web 
page. However, the browser cannot run Python Bytecode or Python Scripts.

Surely, one is going to want to create GUI apps for users that are not Python 
Developers. I would not think to ask someone to install Python on their system 
and make sure it is added to the path. Maybe it is not so hard for the 
non-technical, average users.

I would want to package in some way so that when launched, it installs whatever 
is needed on the end user's computer. How is this done?
Are there common practices for this?
Thanks,
Bruce

On option is pyinstaller or py2exe, which converts a Python script + 
dependencies into a single file (single directory) executable. Sometimes 
you must give them hints what to include, but in general it works well. 
It may create very large packages (if you include 
numpy/scipy/matplotlib, you'll end up with ~60 MB)


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


How does one distribute Tkinter or Qt GUI apps Developed in Python

2015-12-16 Thread Bruce Whealton
I watched one training video that discussed Python and Tkinter. Like many 
similar tutorials from online training sites, I was left scratching my head. 

What seems to be blatantly missing is how this would be distributed. In the 
first mentioned tutorial from Lynda.com the Tkinter app was related to a web 
page. However, the browser cannot run Python Bytecode or Python Scripts. 

Surely, one is going to want to create GUI apps for users that are not Python 
Developers. I would not think to ask someone to install Python on their system 
and make sure it is added to the path. Maybe it is not so hard for the 
non-technical, average users. 

I would want to package in some way so that when launched, it installs whatever 
is needed on the end user's computer. How is this done? 
Are there common practices for this? 
Thanks, 
Bruce
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: error reading api with urllib

2015-12-16 Thread Ian Kelly
On Wed, Dec 16, 2015 at 3:12 PM, John Gordon  wrote:
> In <9aa21642-765b-4666-8c66-a6dab9928...@googlegroups.com> 
> simian...@gmail.com writes:
>
>> Bad Request
>> b''
>
>
> That probably means you aren't using one of the recognized methods
> (i.e. GET, POST, etc.)
>
> It doesn't look like you are specifying one of these methods on your
> Request object.  Try doing that.
>
> (It works in your browser because it defaults to GET automatically.)

urllib.request.Request also defaults to GET unless the request
includes data, in which case it defaults to POST. I would be more
inclined to suspect a problem with the stored procedure being called.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why my image is in bad quality ?

2015-12-16 Thread BartC

On 16/12/2015 21:53, fsn761...@gmail.com wrote:

On Thursday, December 17, 2015 at 1:36:55 AM UTC+4, BartC wrote:



You need to test step by step to see at what point it goes wrong. You're
scaling by 20 (which is a massive amount); what happens when scaling by
1? And anti-alias is turned off? (Which might let you see by how many
pixels each successive line is out and could give a clue.)

It does seem as though something is going amiss with recognising the
image dimensions, or you've inadvertently applied a 'shear' or 'slant'
transformation. (Maybe you can apply a reverse transform to fix it!)

--
Bartc


Original size: 150x30
Original image the same, but without skew (usual upright letters).
When scaling by less than 20 recognition quality is bad (in another code, which 
doesn't use buffer, screenshot, but loads image from a directory).
Antialias makes no difference.
Shear, slant - ok, show me how.


I've played with a 150x30 reduced image. The best I can do is apply a 
shift that makes the letters slant the other way, but at only half the 
angle. Trying to get them upright makes them wobbly. (I did this with 
some code - not Python - that read each pixel and stored it at a shifted 
position. But this is because I'm not familiar with manipulation programs.)


So whatever's gone wrong might be more complex. You should forget about 
recognition quality, and find out what it is that's applying the skew 
(another name for shear or slant). That seems to be being applied before 
the scaling, which is giving the 'steps' in the sloping edges.


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


Re: error reading api with urllib

2015-12-16 Thread Ian Kelly
On Tue, Dec 15, 2015 at 7:46 PM, Simian  wrote:
> I added
>
> except urllib.error.HTTPError as e:
>  print('HTTP Errpr')
>  print('Error code: ', e.code)
>
> to my try and I recieve...
>
> 400: ('Bad Request',
>  'Bad request syntax or unsupported method'),
>
> but processing the string with a browser works fine.

Have you tried requesting the same URL with curl?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: error reading api with urllib

2015-12-16 Thread John Gordon
In <9aa21642-765b-4666-8c66-a6dab9928...@googlegroups.com> simian...@gmail.com 
writes:

> Bad Request
> b''


That probably means you aren't using one of the recognized methods
(i.e. GET, POST, etc.)

It doesn't look like you are specifying one of these methods on your
Request object.  Try doing that.

(It works in your browser because it defaults to GET automatically.)

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Why my image is in bad quality ?

2015-12-16 Thread fsn761304
On Thursday, December 17, 2015 at 1:36:55 AM UTC+4, BartC wrote:
> On 16/12/2015 17:17, fsn761...@gmail.com wrote:
> > ...here is the bad image: http://wikisend.com/download/748118/saved.png
> >
> 
> This is 3000x600 pixels; what was the original size? (150x30?)
> 
> What does the original look like?
> 
> You need to test step by step to see at what point it goes wrong. You're 
> scaling by 20 (which is a massive amount); what happens when scaling by 
> 1? And anti-alias is turned off? (Which might let you see by how many 
> pixels each successive line is out and could give a clue.)
> 
> It does seem as though something is going amiss with recognising the 
> image dimensions, or you've inadvertently applied a 'shear' or 'slant' 
> transformation. (Maybe you can apply a reverse transform to fix it!)
> 
> -- 
> Bartc

Original size: 150x30
Original image the same, but without skew (usual upright letters).
When scaling by less than 20 recognition quality is bad (in another code, which 
doesn't use buffer, screenshot, but loads image from a directory).
Antialias makes no difference.
Shear, slant - ok, show me how.

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


Re: Why my image is in bad quality ?

2015-12-16 Thread BartC

On 16/12/2015 17:17, fsn761...@gmail.com wrote:

...here is the bad image: http://wikisend.com/download/748118/saved.png



This is 3000x600 pixels; what was the original size? (150x30?)

What does the original look like?

You need to test step by step to see at what point it goes wrong. You're 
scaling by 20 (which is a massive amount); what happens when scaling by 
1? And anti-alias is turned off? (Which might let you see by how many 
pixels each successive line is out and could give a clue.)


It does seem as though something is going amiss with recognising the 
image dimensions, or you've inadvertently applied a 'shear' or 'slant' 
transformation. (Maybe you can apply a reverse transform to fix it!)


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


Re: Python 3.1 test issue

2015-12-16 Thread Terry Reedy

On 12/16/2015 1:22 PM, George Trojan wrote:

I installed Python 3.1 on RHEL 7.2.


According to the output below, you installed 3.5.1.  Much better than 
the years old 3.1.



The command make test hangs (or
takes a lot of time on test_subprocess
[396/397] test_subprocess


This indicates that everything up to this point passed, else there would 
be '/1' or higher after '397'.



^C
Test suite interrupted by signal SIGINT.


There is at least one test that normally take a couple of minutes, but 
see below.



5 tests omitted:
 test___all__ test_distutils test_site test_socket test_warnings
381 tests OK.
4 tests altered the execution environment:
 test___all__ test_distutils test_site test_warnings
11 tests skipped:
 test_devpoll test_kqueue test_msilib test_ossaudiodev
 test_startfile test_tix test_tk test_ttk_guionly test_winreg
 test_winsound test_zipfile64
make: *** [test] Error 1

CPU was at 100% all the time for process

gtrojan  15758  8907 94 17:29 pts/6 00:06:47
/home/gtrojan/Downloads/Python-3.5.1/python -R -bb -E -Wdefault
-Werror::BytesWarning -X faulthandler -m test.regrtest --slaveargs


Running 'python -m test -h' displays a long help messages. ('-m test' 
abbreviates '-m test.regrtest' on 3.x.) Option '--slaveargs ARGS' is 
listed without anything said about the meaning of ARGS.  I reformatted 
the ARGS list to make it more readable.



[["test_socket", 0, false],


This appears to pass arguments to a specific test, test_socket. I would 
guess this is done by setting sys.argv. This is the first I knew about 
this.  What follows of a dict of options.  Most could have been set with 
normal --option flags.  Most are the defaults.


>  {"huntrleaks": false,
>   "match_tests": null,
>   "failfast": false,
>   "output_on_failure": false,
>   "use_resources":

["curses", "network", "decimal", "cpu", "subprocess", "urlfetch"],
  "pgo": false,

>   "timeout": null
>  }
> ]

The relevant non-default is 'use_resources'.  In particular, 'cpu' runs 
'certain CPU-heavy tests', and 'subprocess' runs all subprocess tests. 
I ran both 'python -m test -usubprocess test_subprocess' and

'python -m test -ucpu -usubprocess test_subprocess
and both took about the same time and less than a minute.

The only thing that puzzles me is that I don't see '"randomize": true' 
in the dict above, but test_subprocess is 317 in the default 
alphabetical order, not 396.


You might try re-running with defaults: python -m test.

--
Terry Jan Reedy

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


Re: geostationary satellite data

2015-12-16 Thread Robin Koch

Am 16.12.2015 um 18:30 schrieb Peter Pearson:

On Thu, 17 Dec 2015 04:08:02 +1100, Chris Angelico  wrote:

>>

It could be 16 bits per pixel. Without knowing a lot more about the
source of the image and its format, it's hard to say with any
certainty.


Agreed.  It's annoying when an agency goes to the trouble of making
huge datasets available online, but fails to identify the format.


http://www.cpc.ncep.noaa.gov/products/global_precip/html/README

says (among other things):

| Each record is a 9896 x 3298 Fortran array of IR brightness
| temperatures that have been scaled to fit into 1-byte by subtracting
| "75" from each datum. Therefore it is necessary for the user to add a
| value of "75" to each data value when using the data.

HTH a little,

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


Python 3.1 test issue

2015-12-16 Thread George Trojan
I installed Python 3.1 on RHEL 7.2.  The command make test hangs (or 
takes a lot of time) on test_subprocess.


[396/397] test_subprocess
^C
Test suite interrupted by signal SIGINT.
5 tests omitted:
test___all__ test_distutils test_site test_socket test_warnings
381 tests OK.
4 tests altered the execution environment:
test___all__ test_distutils test_site test_warnings
11 tests skipped:
test_devpoll test_kqueue test_msilib test_ossaudiodev
test_startfile test_tix test_tk test_ttk_guionly test_winreg
test_winsound test_zipfile64
make: *** [test] Error 1

CPU was at 100% all the time for process

gtrojan  15758  8907 94 17:29 pts/6 00:06:47 
/home/gtrojan/Downloads/Python-3.5.1/python -R -bb -E -Wdefault 
-Werror::BytesWarning -X faulthandler -m test.regrtest --slaveargs 
[["test_socket", 0, false], {"huntrleaks": false, "match_tests": null, 
"failfast": false, "output_on_failure": false, "use_resources": 
["curses", "network", "decimal", "cpu", "subprocess", "urlfetch"], 
"pgo": false, "timeout": null}]

gtrojan  22889   336  0 17:36 pts/11   00:00:00 grep --color=auto 15758

Is this a problem?

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


Re: geostationary satellite data

2015-12-16 Thread Peter Pearson
On Thu, 17 Dec 2015 04:37:26 +1100, Chris Angelico  wrote:
> On Thu, Dec 17, 2015 at 4:30 AM, Peter Pearson
> wrote:
>> Agreed.  It's annoying when an agency goes to the trouble of making
>> huge datasets available online, but fails to identify the format.
>>
>> But the 16-bits-per-pixel hypothesis is unlikely, given that each
>> byte tends to echo its predecessor:
>>
>> 130        
>> 140    c0ff c1c0 c3c3 c3c3 c4c4
>> 150 c4c4 c3c4 c3c3 c4c4 c3c3 c3c3 c3c3 c3c3
>> 160 c4c4 c4c4 c5c4 c6c5 c7c7 c7c7 c5c5 c6c5
>
> Hmm. With just a few exceptions. Maybe it's two channels or something
> - is that what you mean by "taken at different wavelengths"?

Yes; but as described below, I now think they're taken at different times.

> Definitely it's begging for format identification from the source.

Agreed, again.  But it's hard to set this kind of problem aside.

I split it into two images, thusly:

>>> half = len(rawdata)/2
>>> Image.fromstring("L", (9896, 3298), rawdata[0:half]).save("temp3.png")
>>> Image.fromstring("L", (9896, 3298), rawdata[half:]).save("temp4.png")

Flipping between the resulting two images, one sees slight displacements
of the large-scale swirly structures, so I'm pretty sure the two images
correspond to slightly different times.  (I use the current GOES West
northern-hemisphere image as my desktop, so I'm pretty familiar with the
movements of atmospheric swirly thingies.)

This feels solved-enough to set aside now.

-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: geostationary satellite data

2015-12-16 Thread Chris Angelico
On Thu, Dec 17, 2015 at 4:30 AM, Peter Pearson
 wrote:
> Agreed.  It's annoying when an agency goes to the trouble of making
> huge datasets available online, but fails to identify the format.
>
> But the 16-bits-per-pixel hypothesis is unlikely, given that each
> byte tends to echo its predecessor:
>
> 130        
> 140    c0ff c1c0 c3c3 c3c3 c4c4
> 150 c4c4 c3c4 c3c3 c4c4 c3c3 c3c3 c3c3 c3c3
> 160 c4c4 c4c4 c5c4 c6c5 c7c7 c7c7 c5c5 c6c5

Hmm. With just a few exceptions. Maybe it's two channels or something
- is that what you mean by "taken at different wavelengths"?

Definitely it's begging for format identification from the source.

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


Re: geostationary satellite data

2015-12-16 Thread Peter Pearson
On Thu, 17 Dec 2015 04:08:02 +1100, Chris Angelico  wrote:
> On Thu, Dec 17, 2015 at 4:04 AM, Peter Pearson
> wrote:
>> The file is 65274016 bytes long.  You claim the dimensions are
>> 9896 x 3298, but that comes out to half that number (32637008), so I'll
>> bet the real dimensions are 9896 x 6596, with one byte per pixel.
>> I think this image format is called "raw".
>
> It could be 16 bits per pixel. Without knowing a lot more about the
> source of the image and its format, it's hard to say with any
> certainty.

Agreed.  It's annoying when an agency goes to the trouble of making
huge datasets available online, but fails to identify the format.

But the 16-bits-per-pixel hypothesis is unlikely, given that each
byte tends to echo its predecessor:

130        
140    c0ff c1c0 c3c3 c3c3 c4c4
150 c4c4 c3c4 c3c3 c4c4 c3c3 c3c3 c3c3 c3c3
160 c4c4 c4c4 c5c4 c6c5 c7c7 c7c7 c5c5 c6c5

When you decompose this data file as a one-byte-per-pixel, 9896 x 6596
image, the resulting image shows two nearly identical strips, one above
the other.  That suggests interlacing, except that the top strip has
some "bites" missing that aren't missing from the bottom strip.  My best
guess is that it's just two images glued together, maybe taken at
different wavelengths.

-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why my image is in bad quality ?

2015-12-16 Thread fsn761304
...here is the bad image: http://wikisend.com/download/748118/saved.png
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tk alternative to askopenfilename and askdirectory?

2015-12-16 Thread Ulli Horlacher
Lorenzo Sutton  wrote:

> On 16/12/2015 14:18, Ulli Horlacher wrote:
> > Is there an alternative to Tk's askopenfilename() and askdirectory()?
> >
> > I want to select a files and directories within one widget, but
> > askopenfilename() let me only select files and askdirectory() let me only
> > select directories.
> >
> >
> 
> I guess it would help if you could provide some information on your use 
> case and what you want to achieve ;)

A (Windows) user shall upload files and/or directories.
For this, he needs to select them.
In the current implementation, the user has to decide first whether he
wants to upload a file or a directory. I want to eliminate this step.

http://fex.rus.uni-stuttgart.de/fop/rC2meOrd/X-20151216180501.png

drag&drop works only for files with ASCII filenames.

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: geostationary satellite data

2015-12-16 Thread Chris Angelico
On Thu, Dec 17, 2015 at 4:04 AM, Peter Pearson
 wrote:
> The file is 65274016 bytes long.  You claim the dimensions are
> 9896 x 3298, but that comes out to half that number (32637008), so I'll
> bet the real dimensions are 9896 x 6596, with one byte per pixel.
> I think this image format is called "raw".

It could be 16 bits per pixel. Without knowing a lot more about the
source of the image and its format, it's hard to say with any
certainty.

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


Re: Why my image is in bad quality ?

2015-12-16 Thread fsn761304
On Wednesday, December 16, 2015 at 8:41:23 PM UTC+4, Chris Angelico wrote:
> On Thu, Dec 17, 2015 at 3:33 AM,   wrote:
> > On Wednesday, December 16, 2015 at 6:33:56 PM UTC+4, Chris Angelico wrote:
> >> On Thu, Dec 17, 2015 at 1:21 AM,   wrote:
> >> > I tried also another code (see below) and without scaling by 20 quality 
> >> > of recognition was very bad.
> >> >
> >> > from pytesseract import image_to_string
> >> > from PIL import Image
> >> >
> >> > im = Image.open("screen.png")
> >> > print(im)
> >> > im = im.resize((214*20,26*20), Image.ANTIALIAS)
> >> > print(image_to_string(im))
> >>
> >> If you need to scale by 20x20 to get the text recognition to work, I
> >> would recommend using something other than an anti-alias filter. Omit
> >> the second argument to use a simpler algorithm; you'll get a blocky
> >> result, which might parse more cleanly for you.
> >>
> >> ChrisA
> >
> > It didn't help to recognize words, the main problem is that image is 
> > inclined to the left, like backslash.
> 
> Interesting. I'm not sure what exactly is going on, as I can't see
> your image or the result, but is it possible that the text is getting
> wrapped? Try printing it to a file, then pulling the file up in a text
> editor with word wrap disabled. Maybe it'll look different.
> 
> ChrisA
When I saved image to a directory it was ok (quality) and recognition was good. 
(there are commented string, which saves into dictory: #image.save("saved.png") 
) It seems I did something wrong with image buffer.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: geostationary satellite data

2015-12-16 Thread Peter Pearson
On Wed, 16 Dec 2015 13:19:26 -0200, jorge.conr...@cptec.inpe.br wrote:
>
> I dowmloaded some data from the Mirador NASA site:
>
> http://mirador.gsfc.nasa.gov/cgi-bin/mirador/presentNavigation.pl?tree=project&dataset=Global-merged%20IR%20Brightness%20Temperature%20Data&project=TRMM&dataGroup=Ancillary&version=001&CGISESSID=97f4b9244878c87819b2a1144d31e270
>
> Each data have the dimension:  9896 x 3298 byte.
>
> I used to read the command :
>
> f = open('merg_2015110500_4km-pixel', mode='rb')
>
> image = f.read()
>
> Please, what can I do to visualize this data.

You provide a URL to a web page, but you're opening a file.  Can
you tell us what kind of file you downloaded?

I grabbed a random file from that site, and it arrived with the name
"merg_2015120123_4km-pixel.Z".  After I ran "uncompress" on it, it was
named "merg_2015120123_4km-pixel", which looks much like your filename,
so I guess this is what you've done.  When I dump it as bytes, I get
a lot of this:

0100  ff ff c0 c0 c1 c2 c2 c2  c2 c3 c3 c3 c3 c4 c4 c3
0110  c3 c3 c1 c1 c0 c0 ff ff  ff ff ff ff ff ff c1 c1
0120  c3 c4 c4 c4 c3 c3 c3 c3  c1 ff ff ff ff ff ff ff
0130  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff
0140  ff ff ff ff ff ff ff c0  c0 c1 c3 c3 c3 c3 c4 c4
0150  c4 c4 c4 c3 c3 c3 c4 c4  c3 c3 c3 c3 c3 c3 c3 c3
0160  c4 c4 c4 c4 c4 c5 c5 c6  c7 c7 c7 c7 c5 c5 c5 c6
0170  c6 c6 c6 c6 c4 c4 c4 c4  c4 c3 c3 c3 c3 c3 c3 c3
0180  c2 c2 c2 c3 c3 c3 c4 c4  c4 c4 c4 c4 c4 c5 c5 c6
0190  c6 c6 c6 c6 c6 c7 c7 c7  c7 c7 c7 c7 c7 c7 c7 c7
01a0  c7 c7 c7 c8 c8 c8 c8 c8  c9 c9 c9 c9 c9 c9 c9 c9

The file is 65274016 bytes long.  You claim the dimensions are
9896 x 3298, but that comes out to half that number (32637008), so I'll
bet the real dimensions are 9896 x 6596, with one byte per pixel.
I think this image format is called "raw".

I haven't the time and expertise to settle this for you, but
the solution is probably going to look something like this:

>>> rawdata = open("merg_2015120123_4km-pixel", "rb").read()
>>> from PIL import Image
>>> img = Image.fromstring("L", (9896, 6596), rawdata)
>>> img.save("temp.png")


-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Windows 10 and PYODBC

2015-12-16 Thread paul.hermeneutic
On Dec 15, 2015 1:32 PM, "William Abdo"  wrote:
>
> issue 25875 created
> I put it in the wrong area the first time.
> First time bug tracker user errors.

My apologies, William. I thought bugs.python.org would be the right place
to put it. I was wrong.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: does the order in which the modules are placed in a file matters ?

2015-12-16 Thread Carl Meyer
Hi Ganesh,

On 12/16/2015 09:09 AM, Ganesh Pal wrote:
> Iam on python 2.7 and linux .I need to know if we need to place the
> modules  in a particular or it doesn't matter at all
> 
> order while writing the program

As you've probably already noticed, it usually doesn't matter to Python
(though it can become relevant in certain unusual circular-import
cases). Most people will have some opinion about what constitutes good
style, though. Opinions tend to look something like these (though
details will vary):

1. All imports at the top of the module.
2. Standard library imports, then third-party imports, then local imports.
3. Sometimes the above types of imports are grouped with intervening
blank lines.
4. Sometimes imports are alphabetized within those groups.

> For Example
> 
> import os
> import shlex
> import subprocess
> import time
> import sys
> import logging
> import  plaftform.cluster
> from util import run
> 
> 
> def main():
>  """ ---MAIN--- """
> 
> if __name__ == '__main__':
> main()
> 
> In the above example :
> 
> 1. Iam guessing  may be the python modules like os , shlex etc come
> first and later the user defined modules like import
> plaftform.cluster .etc come latter
> 
> Sorry if my question sounds dump , I was running pep8 and don't see
> its bothered much about it

AFAIK the pep8 module doesn't care about import order. If you'd like to
enforce an import order in your project, you can look at isort. [1]

Carl

  [1] https://pypi.python.org/pypi/isort



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


Re: does the order in which the modules are placed in a file matters ?

2015-12-16 Thread Chris Angelico
On Thu, Dec 17, 2015 at 3:42 AM, Dan Strohl  wrote:
> For the general modules it doesn't matter, however using if you are using any 
> non-standard packages, and If there are duplicate names in any of the modules 
> and if you import them with a "*" (as some packages suggest), it can cause 
> you to end up referring to an object you were not intending to.
>
> [chomp]
>
> Note, using * is dis-recommended, though pretty often done, for more 
> information on using *, see: 
> https://docs.python.org/2/tutorial/modules.html#importing-from-a-package

This is exactly why (well, one of the reasons why) star imports are
generally not recommended. There are a small number of modules that
have promised to keep their namespaces clean in order to make this
viable, but even there, it has issues of confusion. There are a few
good places to use star imports, such as when you wrap one module in
another; I would STRONGLY recommend against using two star imports in
a single file, without being VERY sure of what you're doing.

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


RE: does the order in which the modules are placed in a file matters ?

2015-12-16 Thread Dan Strohl
For the general modules it doesn't matter, however using if you are using any 
non-standard packages, and If there are duplicate names in any of the modules 
and if you import them with a "*" (as some packages suggest), it can cause you 
to end up referring to an object you were not intending to.

For example, if you have found a package called "foo", and the instructions on 
it are to import it as:

from foo import *

Then you have another package called "bar" with the same instructions... so now 
you have:

from foo import *
from bar import *

In both of these there is a class called "snafu", when you do this:

from foo import *
from bar import *

SITUATION = snafu()

You are going to get bar.snafu(), not foo.snafu()

This can of course be gotten around by doing:

import foo
import bar

SITUATION = foo.snafu()

(or a number of other approaches using "as" etc...)

Note, using * is dis-recommended, though pretty often done, for more 
information on using *, see: 
https://docs.python.org/2/tutorial/modules.html#importing-from-a-package 

Dan Strohl


-Original Message-
From: Python-list [mailto:python-list-bounces+d.strohl=f5@python.org] On 
Behalf Of Chris Angelico
Sent: Wednesday, December 16, 2015 8:14 AM
Cc: python-list@python.org
Subject: Re: does the order in which the modules are placed in a file matters ?

On Thu, Dec 17, 2015 at 3:09 AM, Ganesh Pal  wrote:
> Iam on python 2.7 and linux .I need to know if we need to place the 
> modules  in a particular or it doesn't matter at all
>
> order while writing the program
>
> For Example
>
> import os
> import shlex
> import subprocess
> import time
> import sys
> import logging
> import  plaftform.cluster
> from util import run

The order of the import statements is the order the modules will get loaded up. 
As a general rule this won't matter; when it comes to standard library modules, 
you can generally assume that you can put them in any order without it making 
any difference. It's common to order them in some aesthetically-pleasing way 
(maybe alphabetical order, or maybe sort them by the length of the name - 
whatever you like).

There is a broad convention that standard library modules get imported first, 
and modules that are part of the current project get imported afterwards. But 
even that doesn't usually matter very much.

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


Re: Why my image is in bad quality ?

2015-12-16 Thread Chris Angelico
On Thu, Dec 17, 2015 at 3:33 AM,   wrote:
> On Wednesday, December 16, 2015 at 6:33:56 PM UTC+4, Chris Angelico wrote:
>> On Thu, Dec 17, 2015 at 1:21 AM,   wrote:
>> > I tried also another code (see below) and without scaling by 20 quality of 
>> > recognition was very bad.
>> >
>> > from pytesseract import image_to_string
>> > from PIL import Image
>> >
>> > im = Image.open("screen.png")
>> > print(im)
>> > im = im.resize((214*20,26*20), Image.ANTIALIAS)
>> > print(image_to_string(im))
>>
>> If you need to scale by 20x20 to get the text recognition to work, I
>> would recommend using something other than an anti-alias filter. Omit
>> the second argument to use a simpler algorithm; you'll get a blocky
>> result, which might parse more cleanly for you.
>>
>> ChrisA
>
> It didn't help to recognize words, the main problem is that image is inclined 
> to the left, like backslash.

Interesting. I'm not sure what exactly is going on, as I can't see
your image or the result, but is it possible that the text is getting
wrapped? Try printing it to a file, then pulling the file up in a text
editor with word wrap disabled. Maybe it'll look different.

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


Re: Why my image is in bad quality ?

2015-12-16 Thread fsn761304
On Wednesday, December 16, 2015 at 8:34:15 PM UTC+4, fsn7...@gmail.com wrote:
> On Wednesday, December 16, 2015 at 6:33:56 PM UTC+4, Chris Angelico wrote:
> > On Thu, Dec 17, 2015 at 1:21 AM,   wrote:
> > > I tried also another code (see below) and without scaling by 20 quality 
> > > of recognition was very bad.
> > >
> > > from pytesseract import image_to_string
> > > from PIL import Image
> > >
> > > im = Image.open("screen.png")
> > > print(im)
> > > im = im.resize((214*20,26*20), Image.ANTIALIAS)
> > > print(image_to_string(im))
> > 
> > If you need to scale by 20x20 to get the text recognition to work, I
> > would recommend using something other than an anti-alias filter. Omit
> > the second argument to use a simpler algorithm; you'll get a blocky
> > result, which might parse more cleanly for you.
> > 
> > ChrisA
> 
> It didn't help to recognize words, the main problem is that image is inclined 
> to the left, like backslash.

...and sometimes there are green horizontal lines above the image.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why my image is in bad quality ?

2015-12-16 Thread fsn761304
On Wednesday, December 16, 2015 at 6:33:56 PM UTC+4, Chris Angelico wrote:
> On Thu, Dec 17, 2015 at 1:21 AM,   wrote:
> > I tried also another code (see below) and without scaling by 20 quality of 
> > recognition was very bad.
> >
> > from pytesseract import image_to_string
> > from PIL import Image
> >
> > im = Image.open("screen.png")
> > print(im)
> > im = im.resize((214*20,26*20), Image.ANTIALIAS)
> > print(image_to_string(im))
> 
> If you need to scale by 20x20 to get the text recognition to work, I
> would recommend using something other than an anti-alias filter. Omit
> the second argument to use a simpler algorithm; you'll get a blocky
> result, which might parse more cleanly for you.
> 
> ChrisA

It didn't help to recognize words, the main problem is that image is inclined 
to the left, like backslash.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tk alternative to askopenfilename and askdirectory?

2015-12-16 Thread Lorenzo Sutton



On 16/12/2015 14:18, Ulli Horlacher wrote:

Is there an alternative to Tk's askopenfilename() and askdirectory()?

I want to select a files and directories within one widget, but
askopenfilename() let me only select files and askdirectory() let me only
select directories.




I guess it would help if you could provide some information on your use 
case and what you want to achieve ;)


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


Re: geostationary satellite data

2015-12-16 Thread Mark Lawrence

On 16/12/2015 15:19, jorge.conr...@cptec.inpe.br wrote:



Hi,


I dowmloaded some data from the Mirador NASA site:


http://mirador.gsfc.nasa.gov/cgi-bin/mirador/presentNavigation.pl?tree=project&dataset=Global-merged%20IR%20Brightness%20Temperature%20Data&project=TRMM&dataGroup=Ancillary&version=001&CGISESSID=97f4b9244878c87819b2a1144d31e270



Each data have the dimension:  9896 x 3298 byte.


I used to read the command :

f = open('merg_2015110500_4km-pixel', mode='rb')

image = f.read()


Please, what can I do to visualize this data.


Conrado


http://pandas.pydata.org/
http://matplotlib.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: does the order in which the modules are placed in a file matters ?

2015-12-16 Thread Chris Angelico
On Thu, Dec 17, 2015 at 3:09 AM, Ganesh Pal  wrote:
> Iam on python 2.7 and linux .I need to know if we need to place the
> modules  in a particular or it doesn't matter at all
>
> order while writing the program
>
> For Example
>
> import os
> import shlex
> import subprocess
> import time
> import sys
> import logging
> import  plaftform.cluster
> from util import run

The order of the import statements is the order the modules will get
loaded up. As a general rule this won't matter; when it comes to
standard library modules, you can generally assume that you can put
them in any order without it making any difference. It's common to
order them in some aesthetically-pleasing way (maybe alphabetical
order, or maybe sort them by the length of the name - whatever you
like).

There is a broad convention that standard library modules get imported
first, and modules that are part of the current project get imported
afterwards. But even that doesn't usually matter very much.

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


does the order in which the modules are placed in a file matters ?

2015-12-16 Thread Ganesh Pal
Iam on python 2.7 and linux .I need to know if we need to place the
modules  in a particular or it doesn't matter at all

order while writing the program

For Example

import os
import shlex
import subprocess
import time
import sys
import logging
import  plaftform.cluster
from util import run


def main():
 """ ---MAIN--- """

if __name__ == '__main__':
main()

In the above example :

1. Iam guessing  may be the python modules like os , shlex etc come
first and later the user defined modules like import
plaftform.cluster .etc come latter

Sorry if my question sounds dump , I was running pep8 and don't see
its bothered much about it


Regards,
Ganesh
-- 
https://mail.python.org/mailman/listinfo/python-list


geostationary satellite data

2015-12-16 Thread jorge . conrado



Hi,


I dowmloaded some data from the Mirador NASA site:


http://mirador.gsfc.nasa.gov/cgi-bin/mirador/presentNavigation.pl?tree=project&dataset=Global-merged%20IR%20Brightness%20Temperature%20Data&project=TRMM&dataGroup=Ancillary&version=001&CGISESSID=97f4b9244878c87819b2a1144d31e270


Each data have the dimension:  9896 x 3298 byte.


I used to read the command :

f = open('merg_2015110500_4km-pixel', mode='rb')

image = f.read()


Please, what can I do to visualize this data.


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


Re: Help on error " ValueError: For numerical factors, num_columns must be an int "

2015-12-16 Thread Robert
On Wednesday, December 16, 2015 at 6:34:21 AM UTC-5, Mark Lawrence wrote:
> On 16/12/2015 10:44, Robert wrote:
> > Hi,
> >
> > When I run the following code, there is an error:
> >
> > ValueError: For numerical factors, num_columns must be an int
> >
> >
> > 
> > import numpy as np
> > import pandas as pd
> > from patsy import dmatrices
> > from sklearn.linear_model import LogisticRegression
> >
> > X = [0.5,0.75,1.0,1.25,1.5,1.75,1.75,2.0,2.25,2.5,2.75,3.0,3.25,
> > 3.5,4.0,4.25,4.5,4.75,5.0,5.5]
> > y = [0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,1,1,1,1,1]
> >
> > zipped = list(zip(X,y))
> > df = pd.DataFrame(zipped,columns = ['study_hrs','p_or_f'])
> >
> > y, X = dmatrices('p_or_f ~ study_hrs', df, return_type="dataframe")
> > ===
> >
> > I have check 'df' is this type:
> > =
> > type(df)
> > Out[25]: pandas.core.frame.DataFrame
> > =
> >
> > I cannot figure out where the problem is. Can you help me?
> > Thanks.
> >
> > Error message:
> > ..
> >
> >
> > ---
> > ValueErrorTraceback (most recent call last)
> > C:\Users\rj\pyprj\stackoverflow_logisticregression0.py in ()
> >   17 df = pd.DataFrame(zipped,columns = ['study_hrs','p_or_f'])
> >   18
> > ---> 19 y, X = dmatrices('p_or_f ~ study_hrs', df, return_type="dataframe")
> >   20
> >   21 y = np.ravel(y)
> >
> > C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\highlevel.pyc
> >  in dmatrices(formula_like, data, eval_env, NA_action, return_type)
> >  295 eval_env = EvalEnvironment.capture(eval_env, reference=1)
> >  296 (lhs, rhs) = _do_highlevel_design(formula_like, data, eval_env,
> > --> 297   NA_action, return_type)
> >  298 if lhs.shape[1] == 0:
> >  299 raise PatsyError("model is missing required outcome 
> > variables")
> >
> > C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\highlevel.pyc
> >  in _do_highlevel_design(formula_like, data, eval_env, NA_action, 
> > return_type)
> >  150 return iter([data])
> >  151 design_infos = _try_incr_builders(formula_like, 
> > data_iter_maker, eval_env,
> > --> 152   NA_action)
> >  153 if design_infos is not None:
> >  154 return build_design_matrices(design_infos, data,
> >
> > C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\highlevel.pyc
> >  in _try_incr_builders(formula_like, data_iter_maker, eval_env, NA_action)
> >   55   data_iter_maker,
> >   56   eval_env,
> > ---> 57   NA_action)
> >   58 else:
> >   59 return None
> >
> > C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\build.pyc
> >  in design_matrix_builders(termlists, data_iter_maker, eval_env, NA_action)
> >  704 factor_states[factor],
> >  705 num_columns=num_column_counts[factor],
> > --> 706 categories=None)
> >  707 else:
> >  708 assert factor in cat_levels_contrasts
> >
> > C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\design_info.pyc
> >  in __init__(self, factor, type, state, num_columns, categories)
> >   86 if self.type == "numerical":
> >   87 if not isinstance(num_columns, int):
> > ---> 88 raise ValueError("For numerical factors, 
> > num_columns "
> >   89  "must be an int")
> >   90 if categories is not None:
> >
> > ValueError: For numerical factors, num_columns must be an int
> >
> 
> Slap the ValueError into a search engine and the first hit is 
> https://groups.google.com/forum/#!topic/pystatsmodels/KcSzNqDxv-Q
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

Hi,
I don't see a solution to my problem. I find the following demo code from 

https://patsy.readthedocs.org/en/v0.1.0/API-reference.html#patsy.dmatrix

It doesn't work either on the Canopy. Does it work on your computer?
Thanks,

/
demo_data("a", "x", nlevels=3)
Out[134]: 
{'a': ['a1', 'a2', 'a3', 'a1', 'a2', 'a3'],
 'x': array([ 1.76405235,  0.40015721,  0.97873798,  2.2408932 ,  1.86755799,
-0.97727788])}

mat = dmatrix("a + x", demo_data("a", "x", nlevels=3))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why my image is in bad quality ?

2015-12-16 Thread Chris Angelico
On Thu, Dec 17, 2015 at 1:21 AM,   wrote:
> I tried also another code (see below) and without scaling by 20 quality of 
> recognition was very bad.
>
> from pytesseract import image_to_string
> from PIL import Image
>
> im = Image.open("screen.png")
> print(im)
> im = im.resize((214*20,26*20), Image.ANTIALIAS)
> print(image_to_string(im))

If you need to scale by 20x20 to get the text recognition to work, I
would recommend using something other than an anti-alias filter. Omit
the second argument to use a simpler algorithm; you'll get a blocky
result, which might parse more cleanly for you.

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


Re: Why my image is in bad quality ?

2015-12-16 Thread fsn761304
On Wednesday, December 16, 2015 at 6:18:00 PM UTC+4, Denis McMahon wrote:
> On Wed, 16 Dec 2015 06:04:37 -0800, fsn761304 wrote:
> 
> > I'm trying to make OCR-recognition on a screenshot, after screenshot
> > taken it goes to pibxbuffer, which content goes to pytesseract.
> > But after using pixbuffer image quality is bad
> 
> > image = image.resize((width*20,height*20), Image.ANTIALIAS)
> 
> This appears to attempt to extrapolate 400 pixels from each pixel in the 
> original image.
> 
> That only works on TV crime dramas, you can't do it in real life.
> 
> -- 
> Denis McMahon, denismfmcma...@gmail.com

I tried also another code (see below) and without scaling by 20 quality of 
recognition was very bad.

from pytesseract import image_to_string
from PIL import Image

im = Image.open("screen.png")
print(im)
im = im.resize((214*20,26*20), Image.ANTIALIAS)
print(image_to_string(im))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why my image is in bad quality ?

2015-12-16 Thread Denis McMahon
On Wed, 16 Dec 2015 06:04:37 -0800, fsn761304 wrote:

> I'm trying to make OCR-recognition on a screenshot, after screenshot
> taken it goes to pibxbuffer, which content goes to pytesseract.
> But after using pixbuffer image quality is bad

> image = image.resize((width*20,height*20), Image.ANTIALIAS)

This appears to attempt to extrapolate 400 pixels from each pixel in the 
original image.

That only works on TV crime dramas, you can't do it in real life.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Why my image is in bad quality ?

2015-12-16 Thread fsn761304
I'm trying to make OCR-recognition on a screenshot, after screenshot taken it 
goes to pibxbuffer, which content goes to pytesseract.
But after using pixbuffer image quality is bad (I tried to save it in a 
directory, instead of pixbuffer, and looked at it).
Below is the problematic snippets of code, further is the whole function.


pixbufObj = Gdk.pixbuf_get_from_window(window, x, y, width, height)
...
image = Image.frombuffer("RGB", (width, height), 
 pixbufObj.get_pixels(), 'raw', 'RGB', 0, 1)
image = image.resize((width*20,height*20), Image.ANTIALIAS)
...
print(pytesseract.image_to_string(image))


Full function:

def takeScreenshot(self, x, y, width = 150, height = 30):
self.width=width
self.height=height
window = Gdk.get_default_root_window()
#x, y, width, height = window.get_geometry()

#print("The size of the root window is {} x {}".format(width, height))

# get_from_drawable() was deprecated. See:
# https://developer.gnome.org/gtk3/stable/ch24s02.html#id-1.6.3.4.7
pixbufObj = Gdk.pixbuf_get_from_window(window, x, y, width, height)
height = pixbufObj.get_height()
width = pixbufObj.get_width()
image = Image.frombuffer("RGB", (width, height), 
 pixbufObj.get_pixels(), 'raw', 'RGB', 0, 1)
image = image.resize((width*20,height*20), Image.ANTIALIAS)
#image.save("saved.png")
print(pytesseract.image_to_string(image))

print("takenScreenshot:",x,y)
-- 
https://mail.python.org/mailman/listinfo/python-list


Tk alternative to askopenfilename and askdirectory?

2015-12-16 Thread Ulli Horlacher
Is there an alternative to Tk's askopenfilename() and askdirectory()?

I want to select a files and directories within one widget, but
askopenfilename() let me only select files and askdirectory() let me only
select directories.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: subprocess.call with non-ASCII arguments?

2015-12-16 Thread Ulli Horlacher
Dennis Lee Bieber  wrote:

> >I want to create a zip file within a Python 2.7 program on windows.
> >
> >My code:
> >
> >  cmd = ['7za.exe','a','-tzip',archive] + files
> >  status = subprocess.call(cmd)
> >
> My first thought would be...
> 
> WHY spawn an OS dependent subprocess...
> 
> Python has a zipfile library that is portable between OS. Along with
> libraries for gzip, bzip2, and tarfiles...

Great hint!

With the python modules zipfile and tarfile I have no more problems with
non-ASCII filenames! It needed a little bit more programming with
os.walk(), because zipfile cannot add directories recursivly.

S:\>python fexit.py * framstag
Container name: test
creating C:\Users\admin\AppData\Local\Temp\fex\test.zip
zip dist\fexit.exe
zip mf.cmd
zip fex.ico
zip fexit.spec
zip build\fexit\fexit.exe.manifest
zip build\fexit\out00-Analysis.toc
zip build\fexit\out00-EXE.toc
zip build\fexit\out00-PKG.pkg
zip build\fexit\out00-PKG.toc
zip build\fexit\out00-PYZ.pyz
zip build\fexit\out00-PYZ.toc
zip build\fexit\out00-Tree.toc
zip build\fexit\out01-Tree.toc
zip build\fexit\warnfexit.txt
zip fexit.py
zip tar.py
zip zip.py

Recipient: frams...@rus.uni-stuttgart.de
test.zip: 13 MB of 13 MB (100%) 28540 kB/s

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help on error " ValueError: For numerical factors, num_columns must be an int "

2015-12-16 Thread Mark Lawrence

On 16/12/2015 10:44, Robert wrote:

Hi,

When I run the following code, there is an error:

ValueError: For numerical factors, num_columns must be an int



import numpy as np
import pandas as pd
from patsy import dmatrices
from sklearn.linear_model import LogisticRegression

X = [0.5,0.75,1.0,1.25,1.5,1.75,1.75,2.0,2.25,2.5,2.75,3.0,3.25,
3.5,4.0,4.25,4.5,4.75,5.0,5.5]
y = [0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,1,1,1,1,1]

zipped = list(zip(X,y))
df = pd.DataFrame(zipped,columns = ['study_hrs','p_or_f'])

y, X = dmatrices('p_or_f ~ study_hrs', df, return_type="dataframe")
===

I have check 'df' is this type:
=
type(df)
Out[25]: pandas.core.frame.DataFrame
=

I cannot figure out where the problem is. Can you help me?
Thanks.

Error message:
..


---
ValueErrorTraceback (most recent call last)
C:\Users\rj\pyprj\stackoverflow_logisticregression0.py in ()
  17 df = pd.DataFrame(zipped,columns = ['study_hrs','p_or_f'])
  18
---> 19 y, X = dmatrices('p_or_f ~ study_hrs', df, return_type="dataframe")
  20
  21 y = np.ravel(y)

C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\highlevel.pyc
 in dmatrices(formula_like, data, eval_env, NA_action, return_type)
 295 eval_env = EvalEnvironment.capture(eval_env, reference=1)
 296 (lhs, rhs) = _do_highlevel_design(formula_like, data, eval_env,
--> 297   NA_action, return_type)
 298 if lhs.shape[1] == 0:
 299 raise PatsyError("model is missing required outcome variables")

C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\highlevel.pyc
 in _do_highlevel_design(formula_like, data, eval_env, NA_action, return_type)
 150 return iter([data])
 151 design_infos = _try_incr_builders(formula_like, data_iter_maker, 
eval_env,
--> 152   NA_action)
 153 if design_infos is not None:
 154 return build_design_matrices(design_infos, data,

C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\highlevel.pyc
 in _try_incr_builders(formula_like, data_iter_maker, eval_env, NA_action)
  55   data_iter_maker,
  56   eval_env,
---> 57   NA_action)
  58 else:
  59 return None

C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\build.pyc
 in design_matrix_builders(termlists, data_iter_maker, eval_env, NA_action)
 704 factor_states[factor],
 705 num_columns=num_column_counts[factor],
--> 706 categories=None)
 707 else:
 708 assert factor in cat_levels_contrasts

C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\design_info.pyc
 in __init__(self, factor, type, state, num_columns, categories)
  86 if self.type == "numerical":
  87 if not isinstance(num_columns, int):
---> 88 raise ValueError("For numerical factors, num_columns "
  89  "must be an int")
  90 if categories is not None:

ValueError: For numerical factors, num_columns must be an int



Slap the ValueError into a search engine and the first hit is 
https://groups.google.com/forum/#!topic/pystatsmodels/KcSzNqDxv-Q


--
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: Help on error " ValueError: For numerical factors, num_columns must be an int "

2015-12-16 Thread Robert
On Wednesday, December 16, 2015 at 5:57:04 AM UTC-5, Robert wrote:
> On Wednesday, December 16, 2015 at 5:44:21 AM UTC-5, Robert wrote:
> > Hi,
> > 
> > When I run the following code, there is an error:
> > 
> > ValueError: For numerical factors, num_columns must be an int 
> > 
> > 
> > 
> > import numpy as np
> > import pandas as pd
> > from patsy import dmatrices
> > from sklearn.linear_model import LogisticRegression
> > 
> > X = [0.5,0.75,1.0,1.25,1.5,1.75,1.75,2.0,2.25,2.5,2.75,3.0,3.25,
> > 3.5,4.0,4.25,4.5,4.75,5.0,5.5]
> > y = [0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,1,1,1,1,1]
> > 
> > zipped = list(zip(X,y))
> > df = pd.DataFrame(zipped,columns = ['study_hrs','p_or_f'])
> > 
> > y, X = dmatrices('p_or_f ~ study_hrs', df, return_type="dataframe")
> > ===
> > 
> > I have check 'df' is this type:
> > =
> > type(df)
> > Out[25]: pandas.core.frame.DataFrame
> > =
> > 
> > I cannot figure out where the problem is. Can you help me?
> > Thanks.
> > 
> > Error message:
> > ..
> > 
> > 
> > ---
> > ValueErrorTraceback (most recent call last)
> > C:\Users\rj\pyprj\stackoverflow_logisticregression0.py in ()
> >  17 df = pd.DataFrame(zipped,columns = ['study_hrs','p_or_f'])
> >  18 
> > ---> 19 y, X = dmatrices('p_or_f ~ study_hrs', df, return_type="dataframe")
> >  20 
> >  21 y = np.ravel(y)
> > 
> > C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\highlevel.pyc
> >  in dmatrices(formula_like, data, eval_env, NA_action, return_type)
> > 295 eval_env = EvalEnvironment.capture(eval_env, reference=1)
> > 296 (lhs, rhs) = _do_highlevel_design(formula_like, data, eval_env,
> > --> 297   NA_action, return_type)
> > 298 if lhs.shape[1] == 0:
> > 299 raise PatsyError("model is missing required outcome 
> > variables")
> > 
> > C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\highlevel.pyc
> >  in _do_highlevel_design(formula_like, data, eval_env, NA_action, 
> > return_type)
> > 150 return iter([data])
> > 151 design_infos = _try_incr_builders(formula_like, 
> > data_iter_maker, eval_env,
> > --> 152   NA_action)
> > 153 if design_infos is not None:
> > 154 return build_design_matrices(design_infos, data,
> > 
> > C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\highlevel.pyc
> >  in _try_incr_builders(formula_like, data_iter_maker, eval_env, NA_action)
> >  55   data_iter_maker,
> >  56   eval_env,
> > ---> 57   NA_action)
> >  58 else:
> >  59 return None
> > 
> > C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\build.pyc
> >  in design_matrix_builders(termlists, data_iter_maker, eval_env, NA_action)
> > 704 factor_states[factor],
> > 705 num_columns=num_column_counts[factor],
> > --> 706 categories=None)
> > 707 else:
> > 708 assert factor in cat_levels_contrasts
> > 
> > C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\design_info.pyc
> >  in __init__(self, factor, type, state, num_columns, categories)
> >  86 if self.type == "numerical":
> >  87 if not isinstance(num_columns, int):
> > ---> 88 raise ValueError("For numerical factors, 
> > num_columns "
> >  89  "must be an int")
> >  90 if categories is not None:
> > 
> > ValueError: For numerical factors, num_columns must be an int
> 
> BTW, I use Python 2.7 on Canopy. 
> 
> patsy: VERSION0.4.0
> 
> Thanks,

When I use this code snippet, copied from the wb, it is also wrong:

import numpy as np
import pandas as pd
import patsy

time = np.tile([1, 2, 3, 4], 3)
country = np.repeat(['a', 'b', 'c'], 4)
event_int = np.random.randint(0, 2, size=len(time))

df = pd.DataFrame({'event_int':event_int, 'time_day':time, 'country':country})

f0 = 'event_int ~ C(time_day):C(country) - 1'
y,X0 = patsy.dmatrices(f0, df, return_type='dataframe')
print len(X0.columns)

I am new to these packages. I don't know why it is correct for other users.
Thanks,
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help on error " ValueError: For numerical factors, num_columns must be an int "

2015-12-16 Thread Robert
On Wednesday, December 16, 2015 at 5:44:21 AM UTC-5, Robert wrote:
> Hi,
> 
> When I run the following code, there is an error:
> 
> ValueError: For numerical factors, num_columns must be an int 
> 
> 
> 
> import numpy as np
> import pandas as pd
> from patsy import dmatrices
> from sklearn.linear_model import LogisticRegression
> 
> X = [0.5,0.75,1.0,1.25,1.5,1.75,1.75,2.0,2.25,2.5,2.75,3.0,3.25,
> 3.5,4.0,4.25,4.5,4.75,5.0,5.5]
> y = [0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,1,1,1,1,1]
> 
> zipped = list(zip(X,y))
> df = pd.DataFrame(zipped,columns = ['study_hrs','p_or_f'])
> 
> y, X = dmatrices('p_or_f ~ study_hrs', df, return_type="dataframe")
> ===
> 
> I have check 'df' is this type:
> =
> type(df)
> Out[25]: pandas.core.frame.DataFrame
> =
> 
> I cannot figure out where the problem is. Can you help me?
> Thanks.
> 
> Error message:
> ..
> 
> 
> ---
> ValueErrorTraceback (most recent call last)
> C:\Users\rj\pyprj\stackoverflow_logisticregression0.py in ()
>  17 df = pd.DataFrame(zipped,columns = ['study_hrs','p_or_f'])
>  18 
> ---> 19 y, X = dmatrices('p_or_f ~ study_hrs', df, return_type="dataframe")
>  20 
>  21 y = np.ravel(y)
> 
> C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\highlevel.pyc
>  in dmatrices(formula_like, data, eval_env, NA_action, return_type)
> 295 eval_env = EvalEnvironment.capture(eval_env, reference=1)
> 296 (lhs, rhs) = _do_highlevel_design(formula_like, data, eval_env,
> --> 297   NA_action, return_type)
> 298 if lhs.shape[1] == 0:
> 299 raise PatsyError("model is missing required outcome 
> variables")
> 
> C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\highlevel.pyc
>  in _do_highlevel_design(formula_like, data, eval_env, NA_action, return_type)
> 150 return iter([data])
> 151 design_infos = _try_incr_builders(formula_like, data_iter_maker, 
> eval_env,
> --> 152   NA_action)
> 153 if design_infos is not None:
> 154 return build_design_matrices(design_infos, data,
> 
> C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\highlevel.pyc
>  in _try_incr_builders(formula_like, data_iter_maker, eval_env, NA_action)
>  55   data_iter_maker,
>  56   eval_env,
> ---> 57   NA_action)
>  58 else:
>  59 return None
> 
> C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\build.pyc
>  in design_matrix_builders(termlists, data_iter_maker, eval_env, NA_action)
> 704 factor_states[factor],
> 705 num_columns=num_column_counts[factor],
> --> 706 categories=None)
> 707 else:
> 708 assert factor in cat_levels_contrasts
> 
> C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\design_info.pyc
>  in __init__(self, factor, type, state, num_columns, categories)
>  86 if self.type == "numerical":
>  87 if not isinstance(num_columns, int):
> ---> 88 raise ValueError("For numerical factors, num_columns "
>  89  "must be an int")
>  90 if categories is not None:
> 
> ValueError: For numerical factors, num_columns must be an int

BTW, I use Python 2.7 on Canopy. 

patsy: VERSION0.4.0

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


Help on error " ValueError: For numerical factors, num_columns must be an int "

2015-12-16 Thread Robert
Hi,

When I run the following code, there is an error:

ValueError: For numerical factors, num_columns must be an int 



import numpy as np
import pandas as pd
from patsy import dmatrices
from sklearn.linear_model import LogisticRegression

X = [0.5,0.75,1.0,1.25,1.5,1.75,1.75,2.0,2.25,2.5,2.75,3.0,3.25,
3.5,4.0,4.25,4.5,4.75,5.0,5.5]
y = [0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,1,1,1,1,1]

zipped = list(zip(X,y))
df = pd.DataFrame(zipped,columns = ['study_hrs','p_or_f'])

y, X = dmatrices('p_or_f ~ study_hrs', df, return_type="dataframe")
===

I have check 'df' is this type:
=
type(df)
Out[25]: pandas.core.frame.DataFrame
=

I cannot figure out where the problem is. Can you help me?
Thanks.

Error message:
..


---
ValueErrorTraceback (most recent call last)
C:\Users\rj\pyprj\stackoverflow_logisticregression0.py in ()
 17 df = pd.DataFrame(zipped,columns = ['study_hrs','p_or_f'])
 18 
---> 19 y, X = dmatrices('p_or_f ~ study_hrs', df, return_type="dataframe")
 20 
 21 y = np.ravel(y)

C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\highlevel.pyc
 in dmatrices(formula_like, data, eval_env, NA_action, return_type)
295 eval_env = EvalEnvironment.capture(eval_env, reference=1)
296 (lhs, rhs) = _do_highlevel_design(formula_like, data, eval_env,
--> 297   NA_action, return_type)
298 if lhs.shape[1] == 0:
299 raise PatsyError("model is missing required outcome variables")

C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\highlevel.pyc
 in _do_highlevel_design(formula_like, data, eval_env, NA_action, return_type)
150 return iter([data])
151 design_infos = _try_incr_builders(formula_like, data_iter_maker, 
eval_env,
--> 152   NA_action)
153 if design_infos is not None:
154 return build_design_matrices(design_infos, data,

C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\highlevel.pyc
 in _try_incr_builders(formula_like, data_iter_maker, eval_env, NA_action)
 55   data_iter_maker,
 56   eval_env,
---> 57   NA_action)
 58 else:
 59 return None

C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\build.pyc
 in design_matrix_builders(termlists, data_iter_maker, eval_env, NA_action)
704 factor_states[factor],
705 num_columns=num_column_counts[factor],
--> 706 categories=None)
707 else:
708 assert factor in cat_levels_contrasts

C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\design_info.pyc
 in __init__(self, factor, type, state, num_columns, categories)
 86 if self.type == "numerical":
 87 if not isinstance(num_columns, int):
---> 88 raise ValueError("For numerical factors, num_columns "
 89  "must be an int")
 90 if categories is not None:

ValueError: For numerical factors, num_columns must be an int 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How can I remove the first line of a multi-line string?

2015-12-16 Thread Steven D'Aprano
On Wed, 16 Dec 2015 11:42 am, sgar...@gmail.com wrote:

> On Monday, September 2, 2013 at 11:53:32 AM UTC-5, MRAB wrote:
>> On 02/09/2013 17:12, Chris "Kwpolska" Warrick wrote:
>> > On Mon, Sep 2, 2013 at 6:06 PM, Anthony Papillion > > gmail.com> wrote:
>> >> Hello Everyone,
>> >>
>> >> I have a multi-line string and I need to remove the very first line
>> >> from it. How can I do that? I looked at StringIO but I can't seem to
>> >> figure out how to properly use it to remove the first line. Basically,
>> >> I want
>> >> to toss the first line but keep everything else.

The maxsplit parameter to str.split makes this easier than falling off a
greased log:


py> astring = """Hello world,
... How are things?
... Hope you are well.
... Goodbye.
... """
py> astring.split("\n", 1)[1]
'How are things?\nHope you are well.\nGoodbye.\n'



-- 
Steven

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


RE: Windows 10 and PYODBC

2015-12-16 Thread William Abdo
issue 25875 created

I put it in the wrong area the first time.

First time bug tracker user errors.


Respectfully,

William Abdo
Software App Engineer II
NTT America, an NTT Communications Company
Office:   +1 561.912.2434
Email:w.a...@ntta.com
[https://rvip.team-center.net/externals/images/email/ntta.png]
[https://rvip.team-center.net/externals/images/email/ntta-twitter.png]
  [https://rvip.team-center.net/externals/images/email/ntta-linkedin.png] 
   
[https://rvip.team-center.net/externals/images/email/ntta-facebook.png] 
   
[https://rvip.team-center.net/externals/images/email/ntta-youtube.png] 






From: paul.hermeneu...@gmail.com [mailto:paul.hermeneu...@gmail.com]
Sent: Tuesday, December 15, 2015 3:09 PM
To: William Abdo
Cc: python-list@python.org
Subject: RE: Windows 10 and PYODBC


On Dec 15, 2015 12:00 PM, "William Abdo" 
mailto:w.a...@ntta.com>> wrote:
>
> As you wish,
>
> [issue577] PYODBC will not talk to Oracle under Windows 10.

Where is this issue filed? I do not see it on http://bugs.python.org/


This email message is intended for the use of the person to whom it has been 
sent, and may contain information that is confidential or legally protected. If 
you are not the intended recipient or have received this message in error, you 
are not authorized to copy, distribute, or otherwise use this message or its 
attachments. Please notify the sender immediately by return e-mail and 
permanently delete this message and any attachments. NTT America makes no 
warranty that this email is error or virus free. Thank you.


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


sublime textx 3 and python 35

2015-12-16 Thread Yaocheng Frank Yang
Dear Python Team,
I'm trying to install python35 and use sublime text 3 to write code on it. 
After I change the path name to the python app location. I still have some 
problem. I wrote a simple print function in sublime text(I already saved the 
file with .py extension) and the console show "finished in 0.2 s " without 
popping up any window displaying the word I tried to print.
Could you give any of your insights on this issue? Also python 35 is 
automatically installed under my User folder and I for some reason couldn't 
find it from scratch by clikcing on folders(like from My computer to user to 
)
Thanks!
Frank 
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Windows 10 and PYODBC

2015-12-16 Thread William Abdo
As you wish,
[issue577] PYODBC will not talk to Oracle under Windows 10.

Respectfully,

William Abdo
Software App Engineer II
NTT America, an NTT Communications Company
Office:   +1 561.912.2434
Email:w.a...@ntta.com
[https://rvip.team-center.net/externals/images/email/ntta.png]
[https://rvip.team-center.net/externals/images/email/ntta-twitter.png]
  [https://rvip.team-center.net/externals/images/email/ntta-linkedin.png] 
   
[https://rvip.team-center.net/externals/images/email/ntta-facebook.png] 
   
[https://rvip.team-center.net/externals/images/email/ntta-youtube.png] 






From: paul.hermeneu...@gmail.com [mailto:paul.hermeneu...@gmail.com]
Sent: Tuesday, December 15, 2015 1:41 PM
To: William Abdo
Cc: python-list@python.org
Subject: RE: Windows 10 and PYODBC


On Dec 15, 2015 10:34 AM, "William Abdo" 
mailto:w.a...@ntta.com>> wrote:
>
> Yes Paul Hermeneutic , that is correct.
>
> I tried everything I could  however,  I was unable to make PYODBC  talk to 
> Oracle under Windows 10.

It would be of help to everyone if you would file a bug report on the issue 
tracker. http://bugs.python.org/


This email message is intended for the use of the person to whom it has been 
sent, and may contain information that is confidential or legally protected. If 
you are not the intended recipient or have received this message in error, you 
are not authorized to copy, distribute, or otherwise use this message or its 
attachments. Please notify the sender immediately by return e-mail and 
permanently delete this message and any attachments. NTT America makes no 
warranty that this email is error or virus free. Thank you.


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


RE: Windows 10 and PYODBC

2015-12-16 Thread William Abdo
Yes Paul Hermeneutic , that is correct.
I tried everything I could  however,  I was unable to make PYODBC  talk to 
Oracle under Windows 10.
Maybe there are smarter than me that can make this work. For me it was easier 
to just use cx_Oracle for the Oracle connection.



Respectfully,

William Abdo
Software App Engineer II
NTT America, an NTT Communications Company
Office:   +1 561.912.2434
Email:w.a...@ntta.com
[https://rvip.team-center.net/externals/images/email/ntta.png]
[https://rvip.team-center.net/externals/images/email/ntta-twitter.png]
  [https://rvip.team-center.net/externals/images/email/ntta-linkedin.png] 
   
[https://rvip.team-center.net/externals/images/email/ntta-facebook.png] 
   
[https://rvip.team-center.net/externals/images/email/ntta-youtube.png] 






From: paul.hermeneu...@gmail.com [mailto:paul.hermeneu...@gmail.com]
Sent: Tuesday, December 15, 2015 11:34 AM
To: William Abdo
Cc: python-list@python.org
Subject: RE: Windows 10 and PYODBC


On Dec 15, 2015 9:22 AM, "William Abdo" 
mailto:w.a...@ntta.com>> wrote:
>
> So I started a search for an Oracle based ODBC client since PYODBC is still 
> working with the Microsoft DB’s, I tried cx_Oracle and it worked perfectly 
> after I managed to get the parameters correct on the call,

It sounds like PYODBC cannot connect to Oracle on Windows 10. Is that correct?


This email message is intended for the use of the person to whom it has been 
sent, and may contain information that is confidential or legally protected. If 
you are not the intended recipient or have received this message in error, you 
are not authorized to copy, distribute, or otherwise use this message or its 
attachments. Please notify the sender immediately by return e-mail and 
permanently delete this message and any attachments. NTT America makes no 
warranty that this email is error or virus free. Thank you.


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


Re: TypeError: 'float' object is not iterable

2015-12-16 Thread Ben Finney
scarrer...@gmail.com writes:

> Someone stealing my points, I don't know how someone do it, but they
> had stolen some of my points.

Make new points, summarise them succinctly in the Subject field, and be
prepared to defend them.

-- 
 \ “Pinky, are you pondering what I'm pondering?” “I think so, |
  `\ Brain, but there's still a bug stuck in here from last time.” |
_o__)   —_Pinky and The Brain_ |
Ben Finney

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