Question about PANDAS

2014-10-20 Thread flebber
On Windows my advice would be to use the anaconda installer. Linux pip will 
work flawlessly. 

If you install anaconda full then you will have pandas as well as an ipython 
launcher installed. 

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


Re: OS X Menubar in Tkinter

2014-10-20 Thread Gregory Ewing

Ned Deily wrote:
The name that shows up in the menu is derived by OS X from the 
application name in the executing application bundle.


I found a hackish way to change it at run time while
working on PyGUI, but it requires using PyObjC:

  from Foundation import NSBundle

  def change_application_name(new_name):
#  Arrange for the application name to be used as the title
#  of the application menu.
ns_bundle = NSBundle.mainBundle()
  if ns_bundle:
ns_info = ns_bundle.localizedInfoDictionary()
if not ns_info:
  ns_info = ns_bundle.infoDictionary()
if ns_info:
  if ns_info['CFBundleName'] == Python:
ns_info['CFBundleName'] = new_name

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


Re: Quick Question About Setting Up Pytz

2014-10-20 Thread Ryan Shuell
Ok, thanks everyone.  I just need to spend more time with this stuff.  It's
definitely slow going.

On Sat, Oct 18, 2014 at 11:16 PM, Rustom Mody rustompm...@gmail.com wrote:

 On Sunday, October 19, 2014 8:25:53 AM UTC+5:30, Ben Finney wrote:
  Chris Angelico writes:

   Try learning Python itself, rather than playing around with extension
   packages like pytz.

  To be fair, You need to install 'pytz' to work correctly with date and
  time values is correct advice. If the OP doesn't install it early, then
  works with timestamps, problems are inevitable -- at which point oh, you
  needed to do that first will be inevitable. It's lose-lose.

 Yes

  It's a sad fact that MS Windows has completely useless timezone support,
  and this install a third-party package hurdle is a cost that is paid
  by all people trying to set up Python on MS Windows.

 About MS-lacunae Ive nothing to say

 [Just head over to a debian list like users or vote or.. and witness the
 riot going on over systemd... Hard to believe all's right in Linux-land]

 As for this OP and similar problems -- yes python is in a peculiar
 position.
 Because of 'batteries included' beginners can do powerful stuff.
 However sometimes the batteries need to be supplemented.
 And then there's a problem -- its not clear whether
 - the beginner is having classic noob problems.
   Expert just needs to tweak a command a bit and he's sailing
 - the beginner is in somewhat uncharted (research-needed) land -- charting
   the route between mutually complementary AND competing setup tools

   I believe python must be some sort of record setter in this that
 o pip is a replacement for easy_install
 o you install pip with easy_install

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

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


Re: Question about PANDAS

2014-10-20 Thread Ryan Shuell
Thanks guys.  I just feel frustrated that I can't do something useful.
I'm reading all about dictionaries, and types, and touples.  Then I read
about string manipulation and loops; two of my favorite things to do.  Then
I read about logic:
-719 = 833
False

That's great, but it's just not very useful for me.  I thought I could use
Python to do screen scraping.  Right now, I use R to do almost all my
screen scraping.  I used to use Excel, but r is just light years easier to
use, so I'll go with that.  I thought Python may be even easier to use than
R, and perhaps even more powerful too.  However, since I picked up my first
Python book about 3 months ago, I seem to be learning all kinds of useless
things, and no practical things.  When I find cool code samples online, I
can't even get them to run.  Last week I found a small sample of code that
supposedly merges data from several text files in a folder into one single
file.  I played with it for a couple hours, and never got it to work.  In
less than 15 minutes, I could have done the merging task, using Excel,
Access, VB.NET, C#.NET, or even a batch file.

I guess I'll just keep reading these books.  I have 10 books, and I'm most
of the way throguh 4 of them.  So far, none are teaching me anything that I
could use in my role managing financial assets.  Maybe something will click
soon.  I hope so.

Thanks again everyone.


On Sun, Oct 19, 2014 at 10:48 AM, Joel Goldstick joel.goldst...@gmail.com
wrote:

 On Sun, Oct 19, 2014 at 10:19 AM, Mark Lawrence breamore...@yahoo.co.uk
 wrote:
  On 18/10/2014 21:00, ryguy7272 wrote:
 
  I'm trying to install Pandas.  I went to this link.
  https://pypi.python.org/pypi/pandas/0.14.1/#downloads
 
  I downloaded this:  pandas-0.14.1.win32-py2.7.exe (md5)
  I have Python27 installed.
 
  So, I run the executable and re-run my Python script and I get the same
  error as before.
 
 
  Traceback (most recent call last):
 File C:/Python27/stock_data.py, line 3, in module
   import pandas as pd
  ImportError: No module named pandas
 

 What messages did you get when you run the installer?
 Most people use pip to install python packages
 Are you writing code and putting it in C:/Python27/ ? isn't that where
 python is installed.  You should write your code in some directory
 under your user tree.


  I thought I just installed it!  Isn't that what the executable is for?
 It
  seems like 100% of my errors are with uninstalled libraries.  I don't
  understand why there are so, so, so many dependencies running Python.
 Also,
  I don't understand why something isn't installed, right after I just
  installed it.
 
  Can someone please explain the logic to me?
 
  Thanks.
 
 
  Have you actually run any code from the Python tutorial yet?  You can do
  lots of things with Python that require no third party libraries.  In
 fact
  many questions here go I need a solution to this that must be in the
  stdlib.  It strikes me that you're trying to enter an Iron Man
 competition
  before you can crawl.
 
  --
  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



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

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


time.perf_counter in Python 2?

2014-10-20 Thread Florian Lindner
Hello,

I wrote a script that does some time measurements. It uses 
time.perf_counter() from Python 3 which works very well. Now I need to 
backport it to python 2.

Docs say that time.clock() is way to go:

time.clock()
On Unix, return the current processor time as a floating point number 
expressed in seconds. The precision, and in fact the very definition of the 
meaning of “processor time”, depends on that of the C function of the same 
name, but in any case, this is the function to use for benchmarking Python 
or timing algorithms.

On Windows, this function returns wall-clock seconds elapsed since the first 
call to this function, as a floating point number, based on the Win32 
function QueryPerformanceCounter(). The resolution is typically better than 
one microsecond.

But for me it always returns the almost same number, nothing time like:

Python 2.7.3 (default, Feb 27 2014, 19:58:35) 
[GCC 4.6.3] on linux2
Type help, copyright, credits or license for more information.
 import time
 time.clock()
0.03
 time.clock()
0.03
 time.clock()
0.04
 time.clock()
0.04


What's wrong there?

Thanks,
Florian

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


Re: time.perf_counter in Python 2?

2014-10-20 Thread Chris Angelico
On Mon, Oct 20, 2014 at 6:47 PM, Florian Lindner mailingli...@xgm.de wrote:
 time.clock()
 On Unix, return the current processor time as a floating point number
 expressed in seconds. The precision, and in fact the very definition of the
 meaning of “processor time”, depends on that of the C function of the same
 name, but in any case, this is the function to use for benchmarking Python
 or timing algorithms.

 But for me it always returns the almost same number, nothing time like:

You're doing practically no work in there. You're using almost no
processor time - the interpreter's waiting for the user, not actually
busy. If you create a busyloop, you'll see time.clock() go up roughly
linearly:

rosuav@sikorsky:~$ python
Python 2.7.3 (default, Mar 13 2014, 11:03:55)
[GCC 4.7.2] on linux2
Type help, copyright, credits or license for more information.
 import time
 def killtime():
... start=time.time()
... end=time.clock()+1
... while time.clock()end: pass
... return time.time()-start
...
 killtime()
1.0048420429229736
 killtime()
1.004641056060791
 killtime()
1.0081689357757568
 killtime()
1.0019969940185547
 killtime()
1.0044770240783691

This function will do its best to waste one second of CPU time. As you
see, it's taking pretty much exactly one second of wall time to do so
(as measured by time.time()). At the end of a few of these runs,
time.clock() will return a value that's fairly close to 1.0 times the
number of executions of killtime(), as the other work Python's doing
is insignificant by comparison.

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


Re: time.perf_counter in Python 2?

2014-10-20 Thread Peter Otten
Florian Lindner wrote:

 Hello,
 
 I wrote a script that does some time measurements. It uses
 time.perf_counter() from Python 3 which works very well. Now I need to
 backport it to python 2.
 
 Docs say that time.clock() is way to go:
 
 time.clock()
 On Unix, return the current processor time as a floating point number
 expressed in seconds. The precision, and in fact the very definition of
 the meaning of “processor time”, depends on that of the C function of the
 same name, but in any case, this is the function to use for benchmarking
 Python or timing algorithms.
 
 On Windows, this function returns wall-clock seconds elapsed since the
 first call to this function, as a floating point number, based on the
 Win32 function QueryPerformanceCounter(). The resolution is typically
 better than one microsecond.
 
 But for me it always returns the almost same number, nothing time like:
 
 Python 2.7.3 (default, Feb 27 2014, 19:58:35)
 [GCC 4.6.3] on linux2
 Type help, copyright, credits or license for more information.
 import time
 time.clock()
 0.03
 time.clock()
 0.03
 time.clock()
 0.04
 time.clock()
 0.04
 
 
 What's wrong there?

While clock is not the recommended timer on Linux the granularity is still 
higher over here:

 time.clock()
0.06874
 time.clock()
0.069221
 time.clock()
0.069782
 time.clock()
0.070309

That or you can type faster ;)

Here's an excerpt from the 2.7 timeit.py:

if sys.platform == win32:
# On Windows, the best timer is time.clock()
default_timer = time.clock
else:
# On most other platforms the best timer is time.time()
default_timer = time.time

In Python3.4 this has become

default_timer = time.perf_counter

So I'd go with timeit.default_timer().

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


Re: Question about PANDAS

2014-10-20 Thread Mark Lawrence

On 19/10/2014 20:57, Ryan Shuell wrote:


Thanks guys.  I just feel frustrated that I can't do something useful.
I'm reading all about dictionaries, and types, and touples.  Then I read
about string manipulation and loops; two of my favorite things to do.
Then I read about logic:
-719 = 833
False

That's great, but it's just not very useful for me.  I thought I could
use Python to do screen scraping.  Right now, I use R to do almost all
my screen scraping.  I used to use Excel, but r is just light years
easier to use, so I'll go with that.  I thought Python may be even
easier to use than R, and perhaps even more powerful too.  However,
since I picked up my first Python book about 3 months ago, I seem to be
learning all kinds of useless things, and no practical things.  When I
find cool code samples online, I can't even get them to run.  Last week
I found a small sample of code that supposedly merges data from several
text files in a folder into one single file.  I played with it for a
couple hours, and never got it to work.  In less than 15 minutes, I
could have done the merging task, using Excel, Access, VB.NET
http://VB.NET, C#.NET, or even a batch file.

I guess I'll just keep reading these books.  I have 10 books, and I'm
most of the way throguh 4 of them.  So far, none are teaching me
anything that I could use in my role managing financial assets.  Maybe
something will click soon.  I hope so.

Thanks again everyone.



For screen scraping you need Beautiful Soup, but if you can't run 
anything yet and can't install anything yet what is the point?  You can 
read as many books as you like, but until you understand the basics of 
Python and not other languages that you've previously used, you'll get 
precisely nowhere.


--
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: Quick Question About Setting Up Pytz

2014-10-20 Thread Mark Lawrence

On 19/10/2014 21:18, Ryan Shuell wrote:

Ok, thanks everyone.  I just need to spend more time with this stuff.
It's definitely slow going.



Please don't top post on this list, thank you.

--
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: Question about PANDAS

2014-10-20 Thread giacomo boffi
Ryan Shuell ryanshu...@gmail.com writes:

 Thanks guys.  I just feel frustrated that I can't do something useful.

I had read many of your messages in the recent past, and I'm under the
impression that your frustration has more to do with Python the
Infrastructure rather than Python the Language

my suggestions will somehow reiterate what was told you in previous
threads,

 1. scrap everything python from your hard disk and your registry,
using unistall as far as possible

 2. choose ONE flavour of python, either 2.7.x or 3.4.x
- future is with 3.4,
- most exaples you'll find were written (are still written...)
  for 2.7.x

 3. the Pyton distribution from official sources contains piles of
stuff (batteries included is the motto) but you seem interested in
what is called the python scientific stack and this is not
there.

If you want at once the stdlib AND the great majority of the extra
modules you're looking for AND an easy way to install other
packages, there are quite a number of third party distributions
that fit your ticket very well: entought, anaconda, active state,
pyxy, all of them should be good enough but I'n not a Windows guy
and I'm not be able to judge. Anyway, read or ask for advice on
python windows distributions, chose one, _install using the_
_defaults_, STICK WITH THAT DISTRIBUTION, familiarizing with its
infrastructure in terms of installing extra packages, setting
virtual environments, using the development tools it offers etc

in my very humble opinion, you are discomforted by the multiplicity of
the solutions and your quest for the best one... choose one, maybe not
the best one for you but trust me, it will be good enough! as soon as
you'll be in good terms with Python the language and python the
infrastructure, as presented to you by a single language version and a
single 3rd party distribution, you will gather momentum in a very
short time

my best wishes,
g
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OS X Menubar in Tkinter

2014-10-20 Thread Noble Bell
On Sunday, October 19, 2014 7:49:34 PM UTC-5, Ned Deily wrote:
 In article a876c046-18aa-4332-bc9a-b1d1181f2...@googlegroups.com,
 
  Noble Bell nobleb...@gmail.com wrote:
 
  I am using Python 3.4 on Mac OS X and Tinter 8.5. Does anyone have any code 
 
  that they would share with me on how to remove the Python menu in the 
 
  menubar at the top next to the apple'? 
 
  
 
  I would like to have the name of my program there instead and my menu. I 
  can 
 
  add menus but not sure how to do the special menubar. Any help would be 
 
  appreciated.
 
 
 
 The name that shows up in the menu is derived by OS X from the 
 
 application name in the executing application bundle.  If you don't 
 
 package your program up as an OS X application bundle, defaults will be 
 
 used; in the case of Python OS X framework builds, Python provides a 
 
 Python.app within the framework to allow the Python process to be 
 
 automatically promoted to a full OS X gui process.  Probably the 
 
 simplest approach is to use py2app to create a double-clickable app with 
 
 the name you want.  There's an example in an answer to a similar 
 
 question on Stackoverflow.  And there are some old but still relevant 
 
 details documented in the Tcl/TkAqua FAQ.
 
 
 
 https://pypi.python.org/pypi/py2app
 
 http://stackoverflow.com/questions/8695926/remove-default-python-submenu-
 
 with-tkinter-menu-on-mac-osx
 
 http://wiki.tcl.tk/12987
 
 
 
 -- 
 
  Ned Deily,
 
  n...@acm.org

Thank you. I will take a look at all that this afternoon. Seems like I might 
have seen that post on stack overflow but not for sure.
-- 
https://mail.python.org/mailman/listinfo/python-list


formal program verification in python?

2014-10-20 Thread Rustom Mody
A colleague asked me if there were any formal program
verification (or derivation) books which are python based.
Sometimes known as 'Hoare/Dijkstra logic'

I would be pleasantly surprised if there are!
Still... In case anyone knows of any
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about PANDAS

2014-10-20 Thread Johann Hibschman
giacomo boffi pec...@pascolo.net writes:

  2. choose ONE flavour of python, either 2.7.x or 3.4.x
 - future is with 3.4,
 - most exaples you'll find were written (are still written...)
   for 2.7.x

If you're interested in statistics (as comparisons to R suggest), I'd
recommend anaconda.  It comes with pandas built-in, for one.  I'd also
suggest the 3.4 version.  Finally, just over the past few months, we've
crossed over to where 3.4 is fully-functional in the anaconda
distribution.  (For a while statsmodels was the hold-out; matplotlib had
problems before that.  Now, though, all is good.)

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


Re: Is there an easy way to control indents in Python

2014-10-20 Thread Simon Kennedy
On Saturday, 18 October 2014 11:53:16 UTC+1, Steven D'Aprano  wrote:
 I'm curious what aspect of idiomatic Perl code you are referring to. When
 people talk about Perl code dismissively, I normally think of three things:
 
 - excessively long one-liners;
 - excessive use of symbols and sigils (line noise);
 - More Than One [Thousand] Ways To Do It

I'll preface the following by stating that I program in Python as a hobby and 
that the only programming I've done professionally was a few years ago now and 
consisted of a Visual Basic style language (Wonderware Intouch) and a piece of 
software called ABB Sattline.

Not having ever attempted to go beyond even the basics of Perl, the aspect that 
causes me to refer to Perl 'dismissively' as well comment in this thread, is 
that I don't find Perl to be an aesthetically pleasing language and I consider 
Python functions which have no blank lines in them to be a small step towards 
Perl.

Some people do not like Python's indentation rules but for me it's a large part 
of what draws me to program in Python. Spaces for indentation and blank lines 
are both aspects of how I like to program. 

I write in Python because I like to, not because I have to.

I think the only reason I might code a function with no blank lines was if I 
was programming in a language that using blank lines caused it to run too 
slowly.
 
 Are you suggesting that Perl functions tend to be too small? What do you
 consider too small?

No function is too small. A one line function if it helps to describe the 
higher level code where it is called is fine by me.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there an easy way to control indents in Python

2014-10-20 Thread Ian Kelly
On Mon, Oct 20, 2014 at 9:54 AM, Simon Kennedy sffjun...@gmail.com wrote:
 Not having ever attempted to go beyond even the basics of Perl, the aspect 
 that causes me to refer to Perl 'dismissively' as well comment in this 
 thread, is that I don't find Perl to be an aesthetically pleasing language 
 and I consider Python functions which have no blank lines in them to be a 
 small step towards Perl.

 Some people do not like Python's indentation rules but for me it's a large 
 part of what draws me to program in Python. Spaces for indentation and blank 
 lines are both aspects of how I like to program.

 I write in Python because I like to, not because I have to.

 I think the only reason I might code a function with no blank lines was if I 
 was programming in a language that using blank lines caused it to run too 
 slowly.

So to be clear, I'm not talking about taking a function like this
(contrived) example and just removing the blank line:

def find_path(graphdata, start, end):
edges = map(str.split, lines)
graph = collections.defaultdict(list)
for node1, node2, weight in edges:
graph[node1].append((node[2], int(weight)))
graph[node2].append((node[1], int(weight)))

open_heap = [(0, (start,))]
closed_set = set()
while open_heap:
cost, path = heapq.heappop(open_heap)
current_node = path[-1]
if current_node == end:
return path
if current_node in closed_set:
continue
for next_node, weight in graph[current_node]:
heapq.heappush((cost + weight, path + (next_node,)))
closed_set.add(current_node)
else:
raise ValueError(No path from start to end)

Rather, I'm saying that where the blank line is should be the start of
a new function. There would still be a blank line, just no longer
inside the function.

Now, maybe you think there should be more blank lines in the above, in
which case we'll just have to disagree on that point.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there an easy way to control indents in Python

2014-10-20 Thread Ian Kelly
On Mon, Oct 20, 2014 at 11:54 AM, Ian Kelly ian.g.ke...@gmail.com wrote:
 On Mon, Oct 20, 2014 at 9:54 AM, Simon Kennedy sffjun...@gmail.com wrote:
 Not having ever attempted to go beyond even the basics of Perl, the aspect 
 that causes me to refer to Perl 'dismissively' as well comment in this 
 thread, is that I don't find Perl to be an aesthetically pleasing language 
 and I consider Python functions which have no blank lines in them to be a 
 small step towards Perl.

 Some people do not like Python's indentation rules but for me it's a large 
 part of what draws me to program in Python. Spaces for indentation and blank 
 lines are both aspects of how I like to program.

 I write in Python because I like to, not because I have to.

 I think the only reason I might code a function with no blank lines was if I 
 was programming in a language that using blank lines caused it to run too 
 slowly.

 So to be clear, I'm not talking about taking a function like this
 (contrived) example and just removing the blank line:

 def find_path(graphdata, start, end):
 edges = map(str.split, lines)
 graph = collections.defaultdict(list)
 for node1, node2, weight in edges:
 graph[node1].append((node[2], int(weight)))
 graph[node2].append((node[1], int(weight)))

 open_heap = [(0, (start,))]
 closed_set = set()
 while open_heap:
 cost, path = heapq.heappop(open_heap)
 current_node = path[-1]
 if current_node == end:
 return path
 if current_node in closed_set:
 continue
 for next_node, weight in graph[current_node]:
 heapq.heappush((cost + weight, path + (next_node,)))
 closed_set.add(current_node)
 else:
 raise ValueError(No path from start to end)

 Rather, I'm saying that where the blank line is should be the start of
 a new function. There would still be a blank line, just no longer
 inside the function.

 Now, maybe you think there should be more blank lines in the above, in
 which case we'll just have to disagree on that point.

By the way, I didn't test that at all, which is why I've spotted at
least two bugs in it since sending the message.
-- 
https://mail.python.org/mailman/listinfo/python-list


Building lists

2014-10-20 Thread Seymore4Head
I haven't had a lot of practice doing this.  If anyone knows of a site
I would appreciate it.

Will Python work like this:
I am trying to come up with an example and work to it.  Say I want a
Grocery list and it will have a maximum size of 50 items.

I want to do this with one list.
Make a list of 0-50.
Then can I add to that list so the second item will hold something
like cheese, eggs, milk.
Say then I want to add the price of cheese, eggs and milk.
Say then I want to add another list of price of cheese, eggs milk from
another store.

Can this be done starting with just a list of numbers from 0-50?
Please no hints, just answer directly how it is done.

for store in range (50):
print store

How can I add to store where it looks like this:
(0,cheese, 1,eggs 2,milk , 3-50,blank for now)

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


Re: Building lists

2014-10-20 Thread sohcahtoa82
On Monday, October 20, 2014 11:13:17 AM UTC-7, Seymore4Head wrote:
 I haven't had a lot of practice doing this.  If anyone knows of a site
 
 I would appreciate it.
 
 
 
 Will Python work like this:
 
 I am trying to come up with an example and work to it.  Say I want a
 
 Grocery list and it will have a maximum size of 50 items.
 
 
 
 I want to do this with one list.
 
 Make a list of 0-50.
 
 Then can I add to that list so the second item will hold something
 
 like cheese, eggs, milk.
 
 Say then I want to add the price of cheese, eggs and milk.
 
 Say then I want to add another list of price of cheese, eggs milk from
 
 another store.
 
 
 
 Can this be done starting with just a list of numbers from 0-50?
 
 Please no hints, just answer directly how it is done.
 
 
 
 for store in range (50):
 
   print store
 
 
 
 How can I add to store where it looks like this:
 
 (0,cheese, 1,eggs 2,milk , 3-50,blank for now)

Please no hints, just answer directly how it is done.

That's pretty rude.  We're not going to do your homework for you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Building lists

2014-10-20 Thread Seymore4Head
On Mon, 20 Oct 2014 11:18:26 -0700 (PDT), sohcahto...@gmail.com wrote:

On Monday, October 20, 2014 11:13:17 AM UTC-7, Seymore4Head wrote:
 I haven't had a lot of practice doing this.  If anyone knows of a site
 
 I would appreciate it.
 
 
 
 Will Python work like this:
 
 I am trying to come up with an example and work to it.  Say I want a
 
 Grocery list and it will have a maximum size of 50 items.
 
 
 
 I want to do this with one list.
 
 Make a list of 0-50.
 
 Then can I add to that list so the second item will hold something
 
 like cheese, eggs, milk.
 
 Say then I want to add the price of cheese, eggs and milk.
 
 Say then I want to add another list of price of cheese, eggs milk from
 
 another store.
 
 
 
 Can this be done starting with just a list of numbers from 0-50?
 
 Please no hints, just answer directly how it is done.
 
 
 
 for store in range (50):
 
  print store
 
 
 
 How can I add to store where it looks like this:
 
 (0,cheese, 1,eggs 2,milk , 3-50,blank for now)

Please no hints, just answer directly how it is done.

That's pretty rude.  We're not going to do your homework for you.

I said please
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Building lists

2014-10-20 Thread sohcahtoa82
On Monday, October 20, 2014 11:23:36 AM UTC-7, Seymore4Head wrote:
 On Mon, 20 Oct 2014 11:18:26 -0700 (PDT), sohcahtoa82 wrote:
 
 
 
 On Monday, October 20, 2014 11:13:17 AM UTC-7, Seymore4Head wrote:
 
  I haven't had a lot of practice doing this.  If anyone knows of a site
 
  
 
  I would appreciate it.
 
  
 
  
 
  
 
  Will Python work like this:
 
  
 
  I am trying to come up with an example and work to it.  Say I want a
 
  
 
  Grocery list and it will have a maximum size of 50 items.
 
  
 
  
 
  
 
  I want to do this with one list.
 
  
 
  Make a list of 0-50.
 
  
 
  Then can I add to that list so the second item will hold something
 
  
 
  like cheese, eggs, milk.
 
  
 
  Say then I want to add the price of cheese, eggs and milk.
 
  
 
  Say then I want to add another list of price of cheese, eggs milk from
 
  
 
  another store.
 
  
 
  
 
  
 
  Can this be done starting with just a list of numbers from 0-50?
 
  
 
  Please no hints, just answer directly how it is done.
 
  
 
  
 
  
 
  for store in range (50):
 
  
 
 print store
 
  
 
  
 
  
 
  How can I add to store where it looks like this:
 
  
 
  (0,cheese, 1,eggs 2,milk , 3-50,blank for now)
 
 
 
 Please no hints, just answer directly how it is done.
 
 
 
 That's pretty rude.  We're not going to do your homework for you.
 
 
 
 I said please

Oh shit!  It's the magic word!  I better get right on it!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there an easy way to control indents in Python

2014-10-20 Thread Juan Christian
Ok, new code using ?:

import sqlite3

db = sqlite3.connect('db.sqlite')


def create_db():
db.execute('''
CREATE TABLE TOPICS(
ID INT PRIMARY KEY NOT NULL,
URL VARCHAR NOT NULL,
AUTHOR VARCHAR NOT NULL,
MESSAGE VARCHAR NOT NULL
);
''')


def insert_db(_id, url, author, message):
db.execute(INSERT INTO TOPICS (ID, URL, AUTHOR, MESSAGE) VALUES (?, ?,
?, ?), (_id, url, author, message))
db.commit()


def get_db(_id):
cursor = db.execute(SELECT ID, URL, AUTHOR, MESSAGE FROM TOPICS WHERE ID =
?, (_id))
return cursor.fetchone()


if __name__ == '__main__':
create_db()
insert_db(12, 'abc.com', 'a', 'b')
print(get_db(12))
db.close()

-

But now when I execute I get

Traceback (most recent call last):
  File .\sql.py, line 30, in module
print(get_db(12))
  File .\sql.py, line 23, in get_db
cursor = db.execute(SELECT ID, URL, AUTHOR, MESSAGE FROM TOPICS WHERE
ID = ?, (_id))
ValueError: parameters are of unsupported type

-

And the second time, again, I get

Traceback (most recent call last):
  File .\sql.py, line 28, in module
create_db()
  File .\sql.py, line 14, in create_db
''')
sqlite3.OperationalError: table TOPICS already exists

On Mon, Oct 20, 2014 at 3:57 PM, Ian Kelly ian.g.ke...@gmail.com wrote:

 On Mon, Oct 20, 2014 at 11:54 AM, Ian Kelly ian.g.ke...@gmail.com wrote:
  On Mon, Oct 20, 2014 at 9:54 AM, Simon Kennedy sffjun...@gmail.com
 wrote:
  Not having ever attempted to go beyond even the basics of Perl, the
 aspect that causes me to refer to Perl 'dismissively' as well comment in
 this thread, is that I don't find Perl to be an aesthetically pleasing
 language and I consider Python functions which have no blank lines in them
 to be a small step towards Perl.
 
  Some people do not like Python's indentation rules but for me it's a
 large part of what draws me to program in Python. Spaces for indentation
 and blank lines are both aspects of how I like to program.
 
  I write in Python because I like to, not because I have to.
 
  I think the only reason I might code a function with no blank lines was
 if I was programming in a language that using blank lines caused it to run
 too slowly.
 
  So to be clear, I'm not talking about taking a function like this
  (contrived) example and just removing the blank line:
 
  def find_path(graphdata, start, end):
  edges = map(str.split, lines)
  graph = collections.defaultdict(list)
  for node1, node2, weight in edges:
  graph[node1].append((node[2], int(weight)))
  graph[node2].append((node[1], int(weight)))
 
  open_heap = [(0, (start,))]
  closed_set = set()
  while open_heap:
  cost, path = heapq.heappop(open_heap)
  current_node = path[-1]
  if current_node == end:
  return path
  if current_node in closed_set:
  continue
  for next_node, weight in graph[current_node]:
  heapq.heappush((cost + weight, path + (next_node,)))
  closed_set.add(current_node)
  else:
  raise ValueError(No path from start to end)
 
  Rather, I'm saying that where the blank line is should be the start of
  a new function. There would still be a blank line, just no longer
  inside the function.
 
  Now, maybe you think there should be more blank lines in the above, in
  which case we'll just have to disagree on that point.

 By the way, I didn't test that at all, which is why I've spotted at
 least two bugs in it since sending the message.
 --
 https://mail.python.org/mailman/listinfo/python-list

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


Re: Building lists

2014-10-20 Thread MRAB

On 2014-10-20 19:10, Seymore4Head wrote:

I haven't had a lot of practice doing this.  If anyone knows of a site
I would appreciate it.

Will Python work like this:
I am trying to come up with an example and work to it.  Say I want a
Grocery list and it will have a maximum size of 50 items.

I want to do this with one list.
Make a list of 0-50.
Then can I add to that list so the second item will hold something
like cheese, eggs, milk.
Say then I want to add the price of cheese, eggs and milk.
Say then I want to add another list of price of cheese, eggs milk from
another store.

Can this be done starting with just a list of numbers from 0-50?
Please no hints, just answer directly how it is done.

for store in range (50):
print store

How can I add to store where it looks like this:
(0,cheese, 1,eggs 2,milk , 3-50,blank for now)


The grocery list would be a list of the things you want to buy.

There are a number of stores, so that would be a list of stores. For
each store you want the price of each item, so that would be a dict
where the key is the item and the value is the price of that item. That
means it would be a list of dicts.

Does that help?
--
https://mail.python.org/mailman/listinfo/python-list


Re: Is there an easy way to control indents in Python

2014-10-20 Thread Ian Kelly
On Mon, Oct 20, 2014 at 1:04 PM, Juan Christian
juan0christ...@gmail.com wrote:
 Ok, new code using ?:

I suspect you meant to post this to some other thread.

 def get_db(_id):
 cursor = db.execute(SELECT ID, URL, AUTHOR, MESSAGE FROM TOPICS WHERE ID =
 ?, (_id))
 return cursor.fetchone()

(_id) is not a tuple; it's just a parenthesized variable name. To
create a one-element tuple you need a trailing comma: (_id,)

Remember that with the exception of the empty tuple (), tuples are
created by commas, not parentheses.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there an easy way to control indents in Python

2014-10-20 Thread MRAB

On 2014-10-20 20:04, Juan Christian wrote:

Ok, new code using ?:

import sqlite3

db = sqlite3.connect('db.sqlite')


def create_db():
 db.execute('''
CREATE TABLE TOPICS(
ID INT PRIMARY KEY NOT NULL,
URL VARCHAR NOT NULL,
AUTHOR VARCHAR NOT NULL,
MESSAGE VARCHAR NOT NULL
);
''')


def insert_db(_id, url, author, message):
 db.execute(INSERT INTO TOPICS (ID, URL, AUTHOR, MESSAGE) VALUES
(?, ?, ?, ?), (_id, url, author, message))
 db.commit()


def get_db(_id):
cursor = db.execute(SELECT ID, URL, AUTHOR, MESSAGE FROM TOPICS WHERE
ID = ?, (_id))
return cursor.fetchone()


if __name__ == '__main__':
create_db()
insert_db(12, 'abc.com http://abc.com', 'a', 'b')
print(get_db(12))
db.close()

-

But now when I execute I get

Traceback (most recent call last):
   File .\sql.py, line 30, in module
 print(get_db(12))
   File .\sql.py, line 23, in get_db
 cursor = db.execute(SELECT ID, URL, AUTHOR, MESSAGE FROM TOPICS
WHERE ID = ?, (_id))
ValueError: parameters are of unsupported type

-


I'm not certain, but I think that the SQL type is called INTEGER, not
INT.


And the second time, again, I get

Traceback (most recent call last):
   File .\sql.py, line 28, in module
 create_db()
   File .\sql.py, line 14, in create_db
 ''')
sqlite3.OperationalError: table TOPICS already exists


That's because you created the table the last time you ran it.

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


Re: Building lists

2014-10-20 Thread Seymore4Head
On Mon, 20 Oct 2014 20:40:18 +0100, MRAB pyt...@mrabarnett.plus.com
wrote:

On 2014-10-20 19:10, Seymore4Head wrote:
 I haven't had a lot of practice doing this.  If anyone knows of a site
 I would appreciate it.

 Will Python work like this:
 I am trying to come up with an example and work to it.  Say I want a
 Grocery list and it will have a maximum size of 50 items.

 I want to do this with one list.
 Make a list of 0-50.
 Then can I add to that list so the second item will hold something
 like cheese, eggs, milk.
 Say then I want to add the price of cheese, eggs and milk.
 Say then I want to add another list of price of cheese, eggs milk from
 another store.

 Can this be done starting with just a list of numbers from 0-50?
 Please no hints, just answer directly how it is done.

 for store in range (50):
  print store

 How can I add to store where it looks like this:
 (0,cheese, 1,eggs 2,milk , 3-50,blank for now)
  
The grocery list would be a list of the things you want to buy.

There are a number of stores, so that would be a list of stores. For
each store you want the price of each item, so that would be a dict
where the key is the item and the value is the price of that item. That
means it would be a list of dicts.

Does that help?

No.  I am pretty new to Python.

For starters I would like to know if you can make a single item list
and then turn it into a 2 item list.  Is there a command for that?

Do you have to know the number of items the list will have before
making it?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Building lists

2014-10-20 Thread Mark Lawrence

On 20/10/2014 19:33, sohcahto...@gmail.com wrote:


Oh shit!  It's the magic word!  I better get right on it!



While you're at it would you please access this list via 
https://mail.python.org/mailman/listinfo/python-list or read and action 
this https://wiki.python.org/moin/GoogleGroupsPython to prevent us 
seeing double line spacing and single line paragraphs, thanks.


--
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: Building lists

2014-10-20 Thread Ian Kelly
On Mon, Oct 20, 2014 at 1:49 PM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 For starters I would like to know if you can make a single item list
 and then turn it into a 2 item list.  Is there a command for that?

You mean like this?

 the_list = ['first_item']
 the_list.append('second_item')
 the_list
['first_item', 'second_item']
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Building lists

2014-10-20 Thread Mark Lawrence

On 20/10/2014 20:49, Seymore4Head wrote:

On Mon, 20 Oct 2014 20:40:18 +0100, MRAB pyt...@mrabarnett.plus.com
wrote:


On 2014-10-20 19:10, Seymore4Head wrote:

I haven't had a lot of practice doing this.  If anyone knows of a site
I would appreciate it.

Will Python work like this:
I am trying to come up with an example and work to it.  Say I want a
Grocery list and it will have a maximum size of 50 items.

I want to do this with one list.
Make a list of 0-50.
Then can I add to that list so the second item will hold something
like cheese, eggs, milk.
Say then I want to add the price of cheese, eggs and milk.
Say then I want to add another list of price of cheese, eggs milk from
another store.

Can this be done starting with just a list of numbers from 0-50?
Please no hints, just answer directly how it is done.

for store in range (50):
print store

How can I add to store where it looks like this:
(0,cheese, 1,eggs 2,milk , 3-50,blank for now)


The grocery list would be a list of the things you want to buy.

There are a number of stores, so that would be a list of stores. For
each store you want the price of each item, so that would be a dict
where the key is the item and the value is the price of that item. That
means it would be a list of dicts.

Does that help?


No.  I am pretty new to Python.

For starters I would like to know if you can make a single item list
and then turn it into a 2 item list.  Is there a command for that?

Do you have to know the number of items the list will have before
making it?



Python doesn't have commands and no.  Perhaps you'd care to (re)read the 
tutorial.


--
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: Building lists

2014-10-20 Thread Seymore4Head
On Mon, 20 Oct 2014 20:57:52 +0100, Mark Lawrence
breamore...@yahoo.co.uk wrote:

On 20/10/2014 20:49, Seymore4Head wrote:
 On Mon, 20 Oct 2014 20:40:18 +0100, MRAB pyt...@mrabarnett.plus.com
 wrote:

 On 2014-10-20 19:10, Seymore4Head wrote:
 I haven't had a lot of practice doing this.  If anyone knows of a site
 I would appreciate it.

 Will Python work like this:
 I am trying to come up with an example and work to it.  Say I want a
 Grocery list and it will have a maximum size of 50 items.

 I want to do this with one list.
 Make a list of 0-50.
 Then can I add to that list so the second item will hold something
 like cheese, eggs, milk.
 Say then I want to add the price of cheese, eggs and milk.
 Say then I want to add another list of price of cheese, eggs milk from
 another store.

 Can this be done starting with just a list of numbers from 0-50?
 Please no hints, just answer directly how it is done.

 for store in range (50):
print store

 How can I add to store where it looks like this:
 (0,cheese, 1,eggs 2,milk , 3-50,blank for now)

 The grocery list would be a list of the things you want to buy.

 There are a number of stores, so that would be a list of stores. For
 each store you want the price of each item, so that would be a dict
 where the key is the item and the value is the price of that item. That
 means it would be a list of dicts.

 Does that help?

 No.  I am pretty new to Python.

 For starters I would like to know if you can make a single item list
 and then turn it into a 2 item list.  Is there a command for that?

 Do you have to know the number of items the list will have before
 making it?


Python doesn't have commands and no.  Perhaps you'd care to (re)read the 
tutorial.

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


Re: Building lists

2014-10-20 Thread Seymore4Head
On Mon, 20 Oct 2014 13:58:46 -0600, Ian Kelly ian.g.ke...@gmail.com
wrote:

On Mon, Oct 20, 2014 at 1:49 PM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 For starters I would like to know if you can make a single item list
 and then turn it into a 2 item list.  Is there a command for that?

You mean like this?

 the_list = ['first_item']
 the_list.append('second_item')
 the_list
['first_item', 'second_item']


a=(1,2,3)
b=(Red, Green, Blue)
c=(a.b,c)

d=(1,red,a 2,green,b 3,blue,c)

Something like that.
-- 
https://mail.python.org/mailman/listinfo/python-list


Women's Rights in Islam

2014-10-20 Thread BV BV

Women's Rights in Islam

Islam is the sole religion that gave women her rights, these are so many and 
recorded in the Quran verses and the traditional sayings of the prophet, these 
rights are condensed in points here as holy texts, if all written, will take 
many pages.

Equality between man and women

  Islam acquits Eve from the original Sin which lived through generation 
and women have to bear it. In Quran God has remitted this sin the moment it was 
committed.  

  Women have the same spiritual status as men in the eye of God.

 

Female Embryo's rights

  A female embryo, like a male embryo, should be guarded against hereditary 
disease.

Females' rights in infantry 

  While in other religions the birth of a female is not always welcome, the 
birth of a female is celebrated in Islam.

  Females like males should be given beautiful names.

  Females like males are to be given love while still children without any 
preference of one sex over another as stated in the prophet's hadith.

  Islam is against denigrating females in any way especially killing them 
during their infantry- an old custom practiced by the pagan Arabs. 

Rights of Females over Parents 

  Females are to receive the due care and be brought up in the best way( 
God's reward for this is shielding parents against the  hellfire and raising 
their ranks high up to that of the prophet as stated in the hadiths). Even 
Female slaves are to be taught, this is doubly rewarded by God.

  Teaching females is mandatory in Islam.

  A female(married or unmarried) has the right to inherit her father, 
mother, husband , her children, sisters and daughters( Note that Females in 
Judeo-Christianity inherit only from their parents in case no brothers are 
found) 

  A female is not to be killed in wars.

  A female chastity is to be given high care.

  Parents should not favor sons over daughters

  A woman has the right to argue with men even with the prophet himself.

  Women are equal to men as stated in the hadith Women are sisters to men.

  A woman, just like a man, can give someone the right of refuge and 
security among the Muslims.

Rights of Wives

  A female has the right to choose her husband.

  A wife has the right to manage her property and the husband should not 
take any of her property.

  A wife is not responsible for spending on her family, it is not allowed 
for a husband to take a penny from her property.

   

  A wife has the full right to her dowry ( The husband is not to take any  
from it )

  A wife can divorce herself if she doesn't like her husband.

  A husband is responsible for feeding, dwelling, taking the utmost care of 
his wife to the extent that raising a piece of bread to a wife's mouth will be 
rewarded by God)

  A wife should be given her full right in bed and even such an act is 
rewarded by God because the husband and the wife are sinners if they commit 
adultery.

  During menses, contrary to the holy Book, a woman can live among her 
family members and whoever touches her remains clean.

  The best among the Muslims are those who are good to their wives.

As a Mother

  To show how important is the obedience of mothers the prophet says 
paradise is under the feet of mothers.

  Though both the father and the mother are to be given the utmost care, a 
mother should be always at the top priority.

  Mothers  should always be given due care from her children

  A son must not prefer his wife to his mother under any circumstances.

  A Muslim should ask for his parent permission before joining the Muslim 
army, which is engaged in fighting.

  Caring about parents is more preferred to fighting in the cause of God, 
if they are old and need care.

  A mother, like father, is to be given the utmost care and be obeyed even 
if she is not a Muslim.

The rights of the divorced woman in Islam

  The Faith of Islam has ordained certain financial and social obligations 
in the event of divorce, so as to discourage people from resorting to it.

  Islam ordains that when a man divorces his wife, he must pay her the 
delayed dowry agreed upon in the marriage contract, in addition to the expense 
of her maintenance of food, drink and living quarters for a certain period of 
time, known as the  iddat .

  The custody of the children is granted to the mother until they grow up. 
In the event of her death or inability to look after her children, the custody 
of her children is granted to her relations.

  The husband is legally and religiously charged with his children's 
financial maintenance, and for wet nurses to breast feed them even if their 
mother breast feeds them herself, as is stated in the following Quranic verse 
And if they suckle your (offspring) give them their recompense [1][12]

Rights of a widow

   The whole of the Islamic society is responsible for 

Re: Building lists

2014-10-20 Thread Ian Kelly
On Mon, Oct 20, 2014 at 2:23 PM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 On Mon, 20 Oct 2014 13:58:46 -0600, Ian Kelly ian.g.ke...@gmail.com
 wrote:

On Mon, Oct 20, 2014 at 1:49 PM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 For starters I would like to know if you can make a single item list
 and then turn it into a 2 item list.  Is there a command for that?

You mean like this?

 the_list = ['first_item']
 the_list.append('second_item')
 the_list
['first_item', 'second_item']


 a=(1,2,3)
 b=(Red, Green, Blue)
 c=(a.b,c)

 d=(1,red,a 2,green,b 3,blue,c)

 Something like that.

Those are tuples, not lists. Are you trying to create a list of tuples
from a, b, and c? If so, then zip does what you want:

 d = list(zip(a, b, c))
 d
[(1, 'Red', 'a'), (2, 'Green', 'b'), (3, 'Blue', 'c')]

Or do you want all those elements merged into a single list?

 d = list(sum(zip(a, b, c), ()))
 d

[1, 'Red', 'a', 2, 'Green', 'b', 3, 'Blue', 'c']
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Building lists

2014-10-20 Thread John Gordon
In obja4a5ij57rtuaivtvcuqsufhuhk3a...@4ax.com Seymore4Head 
Seymore4Head@Hotmail.invalid writes:

 Will Python work like this:

Python is a capable general-purpose language, so yes, it can pretty
much do anything you want.  The trick is knowing how to do it.

 Make a list of 0-50.
 Then can I add to that list so the second item will hold something
 like cheese, eggs, milk.

You want one item to have cheese, eggs, and milk?  What's the point
of calling it one item if it holds three things?

 Say then I want to add the price of cheese, eggs and milk.
 Say then I want to add another list of price of cheese, eggs milk from
 another store.

 Can this be done starting with just a list of numbers from 0-50?
 Please no hints, just answer directly how it is done.

Each list item could be a tuple consisting of the item name and a dict
containing the item's price at various stores, for example:

# start with an empty list
shopping_list = []

# make a 'cheese' item
cheese = ('Cheese', { 'Walmart' : 5.00,
  'Publix': 5.50,
  'Costco': 4.99 } )

# add cheese to the shopping list
shopping_list.append(cheese)

-- 
John Gordon Imagine what it must be like for a real medical doctor to
gor...@panix.comwatch 'House', or a real serial killer to watch 'Dexter'.

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


Re: Building lists

2014-10-20 Thread Mark Lawrence

On 20/10/2014 21:23, Seymore4Head wrote:

On Mon, 20 Oct 2014 13:58:46 -0600, Ian Kelly ian.g.ke...@gmail.com
wrote:


On Mon, Oct 20, 2014 at 1:49 PM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:

For starters I would like to know if you can make a single item list
and then turn it into a 2 item list.  Is there a command for that?


You mean like this?


the_list = ['first_item']
the_list.append('second_item')
the_list

['first_item', 'second_item']



a=(1,2,3)
b=(Red, Green, Blue)
c=(a.b,c)

d=(1,red,a 2,green,b 3,blue,c)

Something like that.



https://docs.python.org/3/library/functions.html#zip

--
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: Building lists

2014-10-20 Thread Seymore4Head
On Mon, 20 Oct 2014 14:45:19 -0600, Ian Kelly ian.g.ke...@gmail.com
wrote:

On Mon, Oct 20, 2014 at 2:23 PM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 On Mon, 20 Oct 2014 13:58:46 -0600, Ian Kelly ian.g.ke...@gmail.com
 wrote:

On Mon, Oct 20, 2014 at 1:49 PM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 For starters I would like to know if you can make a single item list
 and then turn it into a 2 item list.  Is there a command for that?

You mean like this?

 the_list = ['first_item']
 the_list.append('second_item')
 the_list
['first_item', 'second_item']


 a=(1,2,3)
 b=(Red, Green, Blue)
 c=(a.b,c)

 d=(1,red,a 2,green,b 3,blue,c)

 Something like that.

Those are tuples, not lists. Are you trying to create a list of tuples
from a, b, and c? If so, then zip does what you want:

 d = list(zip(a, b, c))
 d
[(1, 'Red', 'a'), (2, 'Green', 'b'), (3, 'Blue', 'c')]

Or do you want all those elements merged into a single list?

 d = list(sum(zip(a, b, c), ()))
 d

[1, 'Red', 'a', 2, 'Green', 'b', 3, 'Blue', 'c']

I am not sure really.  I know I need more practice, but I haven't
found a reliable way to find practice problems.

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


Re: Building lists

2014-10-20 Thread Seymore4Head
On Mon, 20 Oct 2014 20:48:54 + (UTC), John Gordon
gor...@panix.com wrote:

In obja4a5ij57rtuaivtvcuqsufhuhk3a...@4ax.com Seymore4Head 
Seymore4Head@Hotmail.invalid writes:

 Will Python work like this:

Python is a capable general-purpose language, so yes, it can pretty
much do anything you want.  The trick is knowing how to do it.

 Make a list of 0-50.
 Then can I add to that list so the second item will hold something
 like cheese, eggs, milk.

You want one item to have cheese, eggs, and milk?  What's the point
of calling it one item if it holds three things?

 Say then I want to add the price of cheese, eggs and milk.
 Say then I want to add another list of price of cheese, eggs milk from
 another store.

 Can this be done starting with just a list of numbers from 0-50?
 Please no hints, just answer directly how it is done.

Each list item could be a tuple consisting of the item name and a dict
containing the item's price at various stores, for example:

# start with an empty list
shopping_list = []

# make a 'cheese' item
cheese = ('Cheese', { 'Walmart' : 5.00,
  'Publix': 5.50,
  'Costco': 4.99 } )

# add cheese to the shopping list
shopping_list.append(cheese)

The thing is I am not really sure what I want.  I do know I need more
practice to find out.  Since I am taking a course now, I can't really
ask a direct question and my first example wasn't so good.

I think what I am going to have to have is a master list that keeps
track of several things and I will need to change some of them so I
know that rules out tuples.  

I need more practice examples with indexing and don't know where to
find it.

Thanks

It is hard to ask questions when you don't know all the terms yet.  I
also know that makes it even harder for you guys to answer them.  :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Building lists

2014-10-20 Thread Ian Kelly
On Mon, Oct 20, 2014 at 3:25 PM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 I think what I am going to have to have is a master list that keeps
 track of several things and I will need to change some of them so I
 know that rules out tuples.

It sounds to me like what you really want is a list of class
instances. Define a class to contain the properties that you want to
have for one item in the list. Then create a list to contain multiple
instances of that class.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Building lists

2014-10-20 Thread Gregory Ewing

Seymore4Head wrote:

Say I want a
Grocery list and it will have a maximum size of 50 items.


In Python it's actually easier to deal with variable-sized
lists having no maximum size. Instead of pre-creating a list
of a given size, just start with an empty list and append
things to it.

Unless there's some external reason for a size limit (e.g.
you can't fit more than 50 items in your shopping bag)
there's no need to impose limit at all. You should
certainly start without a limit and only add it later
if needed.

Some things to get you started:

items = [] # Start with an empty list
items.append(cheese) # Add some items to it
items.append(eggs)
items.append(milk)
for item in items: # Process the items
print(item)

If you really need to limit the number of items, you
can do something like this:

def add_item(item):
if len(items)  50:
items.append(item)
else:
raise Exception(Shopping list is full)

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


Re: Flush stdin

2014-10-20 Thread Dan Stromberg
On Sun, Oct 19, 2014 at 9:45 PM, Marko Rauhamaa ma...@pacujo.net wrote:
 I found this comment in CPython's source code (pythonrun.c):

 /* stdin is always opened in buffered mode, first because it shouldn't
make a difference in common use cases, second because TextIOWrapper
depends on the presence of a read1() method which only exists on
buffered streams.
 */

 The solution is to use os.read().

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


Re: Building lists

2014-10-20 Thread Seymore4Head
On Tue, 21 Oct 2014 10:54:55 +1300, Gregory Ewing
greg.ew...@canterbury.ac.nz wrote:

Seymore4Head wrote:
 Say I want a
 Grocery list and it will have a maximum size of 50 items.

In Python it's actually easier to deal with variable-sized
lists having no maximum size. Instead of pre-creating a list
of a given size, just start with an empty list and append
things to it.

Unless there's some external reason for a size limit (e.g.
you can't fit more than 50 items in your shopping bag)
there's no need to impose limit at all. You should
certainly start without a limit and only add it later
if needed.

Some things to get you started:

items = [] # Start with an empty list
items.append(cheese) # Add some items to it
items.append(eggs)
items.append(milk)
for item in items: # Process the items
 print(item)

If you really need to limit the number of items, you
can do something like this:

def add_item(item):
 if len(items)  50:
 items.append(item)
 else:
 raise Exception(Shopping list is full)

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


Re: Is there an easy way to control indents in Python

2014-10-20 Thread Juan Christian
Sorry guys, my post about SQL was not meant to be here!!!

On Mon, Oct 20, 2014 at 5:43 PM, MRAB pyt...@mrabarnett.plus.com wrote:

 On 2014-10-20 20:04, Juan Christian wrote:

 Ok, new code using ?:

 import sqlite3

 db = sqlite3.connect('db.sqlite')


 def create_db():
  db.execute('''
 CREATE TABLE TOPICS(
 ID INT PRIMARY KEY NOT NULL,
 URL VARCHAR NOT NULL,
 AUTHOR VARCHAR NOT NULL,
 MESSAGE VARCHAR NOT NULL
 );
 ''')


 def insert_db(_id, url, author, message):
  db.execute(INSERT INTO TOPICS (ID, URL, AUTHOR, MESSAGE) VALUES
 (?, ?, ?, ?), (_id, url, author, message))
  db.commit()


 def get_db(_id):
 cursor = db.execute(SELECT ID, URL, AUTHOR, MESSAGE FROM TOPICS WHERE
 ID = ?, (_id))
 return cursor.fetchone()


 if __name__ == '__main__':
 create_db()
 insert_db(12, 'abc.com http://abc.com', 'a', 'b')
 print(get_db(12))
 db.close()

 -

 But now when I execute I get

 Traceback (most recent call last):
File .\sql.py, line 30, in module
  print(get_db(12))
File .\sql.py, line 23, in get_db
  cursor = db.execute(SELECT ID, URL, AUTHOR, MESSAGE FROM TOPICS
 WHERE ID = ?, (_id))
 ValueError: parameters are of unsupported type

 -

  I'm not certain, but I think that the SQL type is called INTEGER, not
 INT.

  And the second time, again, I get

 Traceback (most recent call last):
File .\sql.py, line 28, in module
  create_db()
File .\sql.py, line 14, in create_db
  ''')
 sqlite3.OperationalError: table TOPICS already exists

  That's because you created the table the last time you ran it.

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

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


Re: Building lists

2014-10-20 Thread Denis McMahon
On Mon, 20 Oct 2014 20:40:18 +0100, MRAB wrote:

 There are a number of stores, so that would be a list of stores. For
 each store you want the price of each item, so that would be a dict
 where the key is the item and the value is the price of that item. That
 means it would be a list of dicts.
 
 Does that help?

It think it would be a dict of dicts:

shopping = { store1 : { item1: price1, item2: price2, ...  }, 
store2 : { item3: price3, item4: price4, ... }, ... }

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


Re: Building lists

2014-10-20 Thread Denis McMahon
On Mon, 20 Oct 2014 15:49:15 -0400, Seymore4Head wrote:

 For starters I would like to know if you can make a single item list and
 then turn it into a 2 item list.  Is there a command for that?

Yes, it's called assignment. You can for example change a member of a 
list from an string to a tuple such as ( string, number ):

 x = [ fred, jim, susan ]
 x[x.index(jim)] = ( jim, 11, )
 print x
['fred', ('jim', 11), 'susan']

 Do you have to know the number of items the list will have before making
 it?

No. See the append() method of the list object.

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


Re: Building lists

2014-10-20 Thread Seymore4Head
On Mon, 20 Oct 2014 22:40:50 + (UTC), Denis McMahon
denismfmcma...@gmail.com wrote:

On Mon, 20 Oct 2014 15:49:15 -0400, Seymore4Head wrote:

 For starters I would like to know if you can make a single item list and
 then turn it into a 2 item list.  Is there a command for that?

Yes, it's called assignment. You can for example change a member of a 
list from an string to a tuple such as ( string, number ):

 x = [ fred, jim, susan ]
 x[x.index(jim)] = ( jim, 11, )
 print x
['fred', ('jim', 11), 'susan']

 Do you have to know the number of items the list will have before making
 it?

No. See the append() method of the list object.

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


Re: Flush stdin

2014-10-20 Thread Dan Stromberg
If I run the following in one tty:
nc -l localhost 9000 | /tmp/z

...where /tmp/z has just:
#!/usr/bin/python3

import sys

for line in sys.stdin.buffer:
print(line)

And then run the following in another tty on the same computer:
while read line; do echo $line; sleep 1; done  /etc/passwd | nc
localhost 9000

...then everything acts line buffered, or perhaps even character
buffered (the two are pretty indistinguishable in this test).  What I
see is my /etc/passwd file popping out of the nc -l side, one line at
a time, each line one second apart.

I suppose this suggests that it's the client that's sending TCP data
that is buffering.

That, or we're using two different versions of netcat (there are at
least two available).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Flush stdin

2014-10-20 Thread Marko Rauhamaa
Dan Stromberg drsali...@gmail.com:

 On Sun, Oct 19, 2014 at 9:45 PM, Marko Rauhamaa ma...@pacujo.net wrote:
 I found this comment in CPython's source code (pythonrun.c):

 /* stdin is always opened in buffered mode, first because it shouldn't
make a difference in common use cases, second because TextIOWrapper
depends on the presence of a read1() method which only exists on
buffered streams.
 */

 The solution is to use os.read().

 Seriously?

I wasn't joking.


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


Re: Building lists

2014-10-20 Thread MRAB

On 2014-10-20 23:30, Denis McMahon wrote:

On Mon, 20 Oct 2014 20:40:18 +0100, MRAB wrote:


There are a number of stores, so that would be a list of stores. For
each store you want the price of each item, so that would be a dict
where the key is the item and the value is the price of that item. That
means it would be a list of dicts.

Does that help?


It think it would be a dict of dicts:

shopping = { store1 : { item1: price1, item2: price2, ...  },
store2 : { item3: price3, item4: price4, ... }, ... }


The OP never said that the stores have names! :-)
--
https://mail.python.org/mailman/listinfo/python-list


Re: Flush stdin

2014-10-20 Thread Marko Rauhamaa

Dan Stromberg drsali...@gmail.com:

 ...then everything acts line buffered, or perhaps even character
 buffered [...]

 That, or we're using two different versions of netcat (there are at
 least two available).

Let's unconfuse the issue a bit. I'll take line buffering, netcat and
the OS out of the picture.

Here's a character generator (test.sh):

while : ; do
echo -n x
sleep 1
done


and here's a character sink (test.py):

import sys
while True:
c = sys.stdin.read(1)
if not c:
break
print(ord(c[0]))


Then, I run:

$ bash ./test.sh | python3 ./test.py
120
120
120
120


The lines are output at one-second intervals.

That demonstrates that sys.stdin.read(1) does not block for more than
one character. IOW, there is no buffering whatsoever.

If I change the sink a bit: c = sys.stdin.read(5), I get the same
output but at five-second intervals indicating that sys.stdin.read()
calls the underlying os.read() function five times before returning. In
fact, that conclusion is made explicit by running:


$ bash ./test.sh | strace python3 ./test.py
...
read(0, x, 4096)  = 1
read(0, x, 4096)  = 1
read(0, x, 4096)  = 1
read(0, x, 4096)  = 1
read(0, x, 4096)  = 1
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 3), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x7f3143bab000
write(1, 120\n, 4120
)= 4
...


If I modify test.py to call os.read():

import os
while True:
c = os.read(0, 5)
if not c:
break
print(ord(c[0]))


The output is again printed at one-second intervals: no buffering.

Thus, we are back at my suggestion: use os.read() if you don't want
Python to buffer stdin for you.


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


Simple import in python 3 errors with complaint about bytes

2014-10-20 Thread Mike Boyle
I'm modifying an extension written with the c-api to have a datatype of 
quaternions https://github.com/moble/numpy_quaternion, with one of the goals 
being python 3 support.  It works nicely in python 2.7, but for python 3.x 
gives an error that I can't find anywhere on the google.  The directory looks 
like this:

.../site-packages/
    quaternion/
        __init__.py
        numpy_quaternion.so

__init__.py contains a line like this:

    from .numpy_quaternion import quaternion

But when it hits that line, python 3 throws its hands up in disgust:

 python -c 'import quaternion'
Traceback (most recent call last):
  File string, line 1, in module
  File 
/Users/mynamehere/.continuum/anaconda/envs/py3k/lib/python3.4/site-packages/quaternion/__init__.py,
 line 3, in module
    from .numpy_quaternion import quaternion
TypeError: __import__() argument 1 must be str, not bytes

The only thing before that line is `import numpy as np`, which typically works 
just fine.  Obviously, I'm using python3.4 to compile and (attempt to) import 
(with a conda environment), so it's not something as dumb as using the wrong 
python.  Also, this is the result for both me on my laptop and Travis-CI 
https://travis-ci.org/moble/numpy_quaternion, so it doesn't seem to be 
anything peculiar to my installation.  I've posted this question on 
stackoverflow, but haven't gotten much interest; the only responder suggested I 
ask here instead.

Any ideas what's going wrong, or where I can go from here?

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


Re: Simple import in python 3 errors with complaint about bytes

2014-10-20 Thread Chris Kaynor
Are you perhaps doing an import inside of the C code?

Chris

On Mon, Oct 20, 2014 at 4:29 PM, Mike Boyle moboyl...@outlook.com wrote:

 I'm modifying an extension written with the c-api to have a datatype of
 quaternions https://github.com/moble/numpy_quaternion, with one of the
 goals being python 3 support.  It works nicely in python 2.7, but for
 python 3.x gives an error that I can't find anywhere on the google.  The
 directory looks like this:

 .../site-packages/
 quaternion/
 __init__.py
 numpy_quaternion.so

 __init__.py contains a line like this:

 from .numpy_quaternion import quaternion

 But when it hits that line, python 3 throws its hands up in disgust:

  python -c 'import quaternion'
 Traceback (most recent call last):
   File string, line 1, in module
   File
 /Users/mynamehere/.continuum/anaconda/envs/py3k/lib/python3.4/site-packages/quaternion/__init__.py,
 line 3, in module
 from .numpy_quaternion import quaternion
 TypeError: __import__() argument 1 must be str, not bytes

 The only thing before that line is `import numpy as np`, which typically
 works just fine.  Obviously, I'm using python3.4 to compile and (attempt
 to) import (with a conda environment), so it's not something as dumb as
 using the wrong python.  Also, this is the result for both me on my laptop
 and Travis-CI https://travis-ci.org/moble/numpy_quaternion, so it
 doesn't seem to be anything peculiar to my installation.  I've posted this
 question on stackoverflow, but haven't gotten much interest; the only
 responder suggested I ask here instead.

 Any ideas what's going wrong, or where I can go from here?

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

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


Re: Simple import in python 3 errors with complaint about bytes

2014-10-20 Thread Ian Kelly
On Mon, Oct 20, 2014 at 5:29 PM, Mike Boyle moboyl...@outlook.com wrote:
 I'm modifying an extension written with the c-api to have a datatype of 
 quaternions https://github.com/moble/numpy_quaternion, with one of the 
 goals being python 3 support.  It works nicely in python 2.7, but for python 
 3.x gives an error that I can't find anywhere on the google.  The directory 
 looks like this:

 .../site-packages/
 quaternion/
 __init__.py
 numpy_quaternion.so

 __init__.py contains a line like this:

 from .numpy_quaternion import quaternion

 But when it hits that line, python 3 throws its hands up in disgust:

 python -c 'import quaternion'
 Traceback (most recent call last):
   File string, line 1, in module
   File 
 /Users/mynamehere/.continuum/anaconda/envs/py3k/lib/python3.4/site-packages/quaternion/__init__.py,
  line 3, in module
 from .numpy_quaternion import quaternion
 TypeError: __import__() argument 1 must be str, not bytes

 The only thing before that line is `import numpy as np`, which typically 
 works just fine.  Obviously, I'm using python3.4 to compile and (attempt to) 
 import (with a conda environment), so it's not something as dumb as using the 
 wrong python.  Also, this is the result for both me on my laptop and 
 Travis-CI https://travis-ci.org/moble/numpy_quaternion, so it doesn't seem 
 to be anything peculiar to my installation.  I've posted this question on 
 stackoverflow, but haven't gotten much interest; the only responder suggested 
 I ask here instead.

 Any ideas what's going wrong, or where I can go from here?

I question whether the error is really coming from that particular
import line.  Try shadowing the __import__ function to see what's
actually being passed there.  E.g.:

 orig_import = __import__
 def debug_import(name, globals=None, locals=None, fromlist=(), level=0):
...   print(debug_import:, name, globals, locals, fromlist, level)
...   return orig_import(name, globals, locals, fromlist, level)
...
 import builtins
 builtins.__import__ = debug_import
 import sys
debug_import: sys {'__spec__': None, '__loader__': class
'_frozen_importlib.BuiltinImporter', '__package__': None, 'builtins':
module 'builtins' (built-in), 'orig_import': built-in function
__import__, '__builtins__': module 'builtins' (built-in),
'__name__': '__main__', '__doc__': None, 'debug_import': function
debug_import at 0x7f6096aac9d8} {'__spec__': None, '__loader__':
class '_frozen_importlib.BuiltinImporter', '__package__': None,
'builtins': module 'builtins' (built-in), 'orig_import': built-in
function __import__, '__builtins__': module 'builtins' (built-in),
'__name__': '__main__', '__doc__': None, 'debug_import': function
debug_import at 0x7f6096aac9d8} None 0
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Simple import in python 3 errors with complaint about bytes

2014-10-20 Thread Chris Angelico
On Tue, Oct 21, 2014 at 10:29 AM, Mike Boyle moboyl...@outlook.com wrote:
 But when it hits that line, python 3 throws its hands up in disgust:

 python -c 'import quaternion'

Just something crazy to try: Instead of using python -c, create an
actual script with just that one line in it. It might be that you have
some strange console config that's causing problems.

You may also want to try changing all your names to be unique
(quaternion1 as the package name, quaternion2 as the Python file
in it, etc), which should tell you which one it's actually failing on.

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


Re: Building lists

2014-10-20 Thread Steven D'Aprano
Seymore4Head wrote:

 For starters I would like to know if you can make a single item list
 and then turn it into a 2 item list.  Is there a command for that?
 
 Do you have to know the number of items the list will have before
 making it?

Now these are the right sort of questions that you should be asking!

They are concrete and tightly focused, not vague and so broad that they
could mean anything, and they invite a concrete answer rather than hints.

First question: can you take a single list item and turn it into a 2-item
list? Yes, you can, you can turn a single list item into *anything*,
including deleting it. Start with a list, and remember that lists are
indexed starting with 0:

py alist = [1, 2, 4, 8, 16, 32, 64]
py alist[0] = hello!
py alist[1] = [a, b, c]
py del alist[4]
py print(alist)
['hello!', ['a', 'b', 'c'], 4, 8, 32, 64]


Second question: do you need to know the number of items in a list in
advance? No. You can add additional items to an existing list with the
append() method:

py import random
py alist = []
py while random.random()  0.5:
... alist.append(spam)
...
py print(alist)
['spam', 'spam']


Because this is random, if you try it you will get an unpredictable number
of spam words in the list. About half the time it will contain no words
at all, about a quarter of the time it will contain a single word, an
eighth of the time it will contain two words, and so forth.


-- 
Steven

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


Re: Building lists

2014-10-20 Thread Seymore4Head
On Tue, 21 Oct 2014 10:55:08 +1100, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:

Seymore4Head wrote:

 For starters I would like to know if you can make a single item list
 and then turn it into a 2 item list.  Is there a command for that?
 
 Do you have to know the number of items the list will have before
 making it?

Now these are the right sort of questions that you should be asking!

They are concrete and tightly focused, not vague and so broad that they
could mean anything, and they invite a concrete answer rather than hints.

First question: can you take a single list item and turn it into a 2-item
list? Yes, you can, you can turn a single list item into *anything*,
including deleting it. Start with a list, and remember that lists are
indexed starting with 0:

py alist = [1, 2, 4, 8, 16, 32, 64]
py alist[0] = hello!
py alist[1] = [a, b, c]
py del alist[4]
py print(alist)
['hello!', ['a', 'b', 'c'], 4, 8, 32, 64]


Second question: do you need to know the number of items in a list in
advance? No. You can add additional items to an existing list with the
append() method:

py import random
py alist = []
py while random.random()  0.5:
... alist.append(spam)
...
py print(alist)
['spam', 'spam']


Because this is random, if you try it you will get an unpredictable number
of spam words in the list. About half the time it will contain no words
at all, about a quarter of the time it will contain a single word, an
eighth of the time it will contain two words, and so forth.

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


RE: Simple import in python 3 errors with complaint about bytes

2014-10-20 Thread Mike Boyle
Ah, yes.  Thanks to that clever import debug hack, and the suggestion that it 
would actually be an import within the module causing the trouble, I managed to 
track it down.  I had tried copying some py3k changes from the rational 
module in numpy/numpy-dtypes, but evidently didn't do it right, or it just 
doesn't work.  I was using `PyImport_Import` with a PyString.  Now, going back 
to the original `PyImport_ImportModule` with a literal `char*`, everything 
seems to work great (for me at least; Travis isn't so sure...).

Thanks very much!





 From: ian.g.ke...@gmail.com
 Date: Mon, 20 Oct 2014 17:48:23 -0600
 Subject: Re: Simple import in python 3 errors with complaint about bytes
 To: python-list@python.org

 On Mon, Oct 20, 2014 at 5:29 PM, Mike Boyle moboyl...@outlook.com wrote:
 I'm modifying an extension written with the c-api to have a datatype of 
 quaternions https://github.com/moble/numpy_quaternion, with one of the 
 goals being python 3 support. It works nicely in python 2.7, but for python 
 3.x gives an error that I can't find anywhere on the google. The directory 
 looks like this:

 .../site-packages/
 quaternion/
 __init__.py
 numpy_quaternion.so

 __init__.py contains a line like this:

 from .numpy_quaternion import quaternion

 But when it hits that line, python 3 throws its hands up in disgust:

 python -c 'import quaternion'
 Traceback (most recent call last):
 File string, line 1, in module
 File 
 /Users/mynamehere/.continuum/anaconda/envs/py3k/lib/python3.4/site-packages/quaternion/__init__.py,
  line 3, in module
 from .numpy_quaternion import quaternion
 TypeError: __import__() argument 1 must be str, not bytes

 The only thing before that line is `import numpy as np`, which typically 
 works just fine. Obviously, I'm using python3.4 to compile and (attempt to) 
 import (with a conda environment), so it's not something as dumb as using 
 the wrong python. Also, this is the result for both me on my laptop and 
 Travis-CI https://travis-ci.org/moble/numpy_quaternion, so it doesn't seem 
 to be anything peculiar to my installation. I've posted this question on 
 stackoverflow, but haven't gotten much interest; the only responder 
 suggested I ask here instead.

 Any ideas what's going wrong, or where I can go from here?

 I question whether the error is really coming from that particular
 import line. Try shadowing the __import__ function to see what's
 actually being passed there. E.g.:

 orig_import = __import__
 def debug_import(name, globals=None, locals=None, fromlist=(), level=0):
 ... print(debug_import:, name, globals, locals, fromlist, level)
 ... return orig_import(name, globals, locals, fromlist, level)
 ...
 import builtins
 builtins.__import__ = debug_import
 import sys
 debug_import: sys {'__spec__': None, '__loader__': class
 '_frozen_importlib.BuiltinImporter', '__package__': None, 'builtins':
 module 'builtins' (built-in), 'orig_import': built-in function
 __import__, '__builtins__': module 'builtins' (built-in),
 '__name__': '__main__', '__doc__': None, 'debug_import': function
 debug_import at 0x7f6096aac9d8} {'__spec__': None, '__loader__':
 class '_frozen_importlib.BuiltinImporter', '__package__': None,
 'builtins': module 'builtins' (built-in), 'orig_import': built-in
 function __import__, '__builtins__': module 'builtins' (built-in),
 '__name__': '__main__', '__doc__': None, 'debug_import': function
 debug_import at 0x7f6096aac9d8} None 0
 --
 https://mail.python.org/mailman/listinfo/python-list
  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Flush stdin

2014-10-20 Thread Dan Stromberg
On Mon, Oct 20, 2014 at 4:18 PM, Marko Rauhamaa ma...@pacujo.net wrote:
 Dan Stromberg drsali...@gmail.com:
 ...then everything acts line buffered, or perhaps even character
 buffered [...]

 That, or we're using two different versions of netcat (there are at
 least two available).

 Let's unconfuse the issue a bit. I'll take line buffering, netcat and
 the OS out of the picture.

 Here's a character generator (test.sh):
 
 while : ; do
 echo -n x
 sleep 1
 done
 

 and here's a character sink (test.py):
 
 import sys
 while True:
 c = sys.stdin.read(1)
 if not c:
 break
 print(ord(c[0]))
 

 Then, I run:
 
 $ bash ./test.sh | python3 ./test.py
 120
 120
 120
 120
 

 The lines are output at one-second intervals.

 That demonstrates that sys.stdin.read(1) does not block for more than
 one character. IOW, there is no buffering whatsoever.

Aren't character-buffered and unbuffered synonymous?

Often with TCP protocols, line buffered is preferred to character
buffered, both for performance and for simplicity: it doesn't suffer
from tinygrams (as much), and telnet becomes a useful test client.

Also, it's a straightforward way of framing your data, to avoid
getting messed up by Nagle or fragmentation.  One might find
http://stromberg.dnsalias.org/~strombrg/bufsock.html worth a glance.
It's buffered, but it keeps things framed, and doesn't fall prey to
tinygrams nearly as much as character buffering.

 If I change the sink a bit: c = sys.stdin.read(5), I get the same
 output but at five-second intervals indicating that sys.stdin.read()
 calls the underlying os.read() function five times before returning. In
 fact, that conclusion is made explicit by running:

 
 $ bash ./test.sh | strace python3 ./test.py
 ...
 read(0, x, 4096)  = 1
 read(0, x, 4096)  = 1
 read(0, x, 4096)  = 1
 read(0, x, 4096)  = 1
 read(0, x, 4096)  = 1
 fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 3), ...}) = 0
 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
 0x7f3143bab000
 write(1, 120\n, 4120
 )= 4
 ...


This is tremendously inefficient.  It demands a context switch for
every character.

 If I modify test.py to call os.read():
 
 import os
 while True:
 c = os.read(0, 5)
 if not c:
 break
 print(ord(c[0]))
 

 The output is again printed at one-second intervals: no buffering.

 Thus, we are back at my suggestion: use os.read() if you don't want
 Python to buffer stdin for you.

It's true that Python won't buffer (or will be character-buffered)
then, but that takes some potentially-salient elements out of the
picture.  IOW, I don't think Python reading unbuffered is necessarily
the whole issue, and may even be going to far.

I have a habit of saying necessary, but not necessarily sufficient,
but in this case I believe it's more of a not necessarily necessary,
and not necessarily sufficient.  A lot depends on the other pieces of
the puzzle that you've chosen to unconfuse away.  Yes, you can make
Python unbuffered/character-buffered, but that's not the whole story.
-- 
https://mail.python.org/mailman/listinfo/python-list


Py2App - Could not import Tkinter error from resulting app

2014-10-20 Thread Noble Bell
I have just created a python 3.4 application and created the setup.py file and 
then created an app with py2app.

When I ran the resulting application I get an error in the console telling me 
that it could not import tkinter.

Any ideas on how to correct this? Did I do something wrong?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OS X Menubar in Tkinter

2014-10-20 Thread Noble Bell
On Monday, October 20, 2014 5:47:14 AM UTC-5, Noble Bell wrote:
 On Sunday, October 19, 2014 7:49:34 PM UTC-5, Ned Deily wrote:
 
  In article a876c046-18aa-4332-bc9a-b1d1181f2...@googlegroups.com,
 
  
 
   Noble Bell nobleb...@gmail.com wrote:
 
  
 
   I am using Python 3.4 on Mac OS X and Tinter 8.5. Does anyone have any 
   code 
 
  
 
   that they would share with me on how to remove the Python menu in the 
 
  
 
   menubar at the top next to the apple'? 
 
  
 
   
 
  
 
   I would like to have the name of my program there instead and my menu. I 
   can 
 
  
 
   add menus but not sure how to do the special menubar. Any help would be 
 
  
 
   appreciated.
 
  
 
  
 
  
 
  The name that shows up in the menu is derived by OS X from the 
 
  
 
  application name in the executing application bundle.  If you don't 
 
  
 
  package your program up as an OS X application bundle, defaults will be 
 
  
 
  used; in the case of Python OS X framework builds, Python provides a 
 
  
 
  Python.app within the framework to allow the Python process to be 
 
  
 
  automatically promoted to a full OS X gui process.  Probably the 
 
  
 
  simplest approach is to use py2app to create a double-clickable app with 
 
  
 
  the name you want.  There's an example in an answer to a similar 
 
  
 
  question on Stackoverflow.  And there are some old but still relevant 
 
  
 
  details documented in the Tcl/TkAqua FAQ.
 
  
 
  
 
  
 
  https://pypi.python.org/pypi/py2app
 
  
 
  http://stackoverflow.com/questions/8695926/remove-default-python-submenu-
 
  
 
  with-tkinter-menu-on-mac-osx
 
  
 
  http://wiki.tcl.tk/12987
 
  
 
  
 
  
 
  -- 
 
  
 
   Ned Deily,
 
  
 
   n...@acm.org
 
 
 
 Thank you. I will take a look at all that this afternoon. Seems like I might 
 have seen that post on stack overflow but not for sure.

Creating the app with py2app fixed my problem. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sqlite3 help

2014-10-20 Thread Chuck
Thanks a bunch Sibylle!  That seems like a better approach.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Py2App - Could not import Tkinter error from resulting app

2014-10-20 Thread Terry Reedy

On 10/20/2014 9:29 PM, Noble Bell wrote:

I have just created a python 3.4 application and created the setup.py file and 
then created an app with py2app.

When I ran the resulting application I get an error in the console telling me 
that it could not import tkinter.

Any ideas on how to correct this? Did I do something wrong?


tkinter imports _tkinter
_tkinter connects with tclx.dll and tkx.dll (x is variable)
So one possibility is no accessible tcl/tx.  I have no idea how py2app 
is supposed to handle this on your undisclosed system.


--
Terry Jan Reedy

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


Re: Flush stdin

2014-10-20 Thread Marko Rauhamaa
Dan Stromberg drsali...@gmail.com:

 Often with TCP protocols, line buffered is preferred to character
 buffered,

Terminal devices support line buffering on write.

Line buffering on read is an illusion created by higher-level libraries.
The low-level read function reads in blocks of bytes.

 Also, it's a straightforward way of framing your data, to avoid
 getting messed up by Nagle or fragmentation.

Nagle affects the communication between the peer OS kernels and isn't
directly related to anything the application does. Also, Nagle doesn't
play any role with pipes.

 
 $ bash ./test.sh | strace python3 ./test.py
 ...
 read(0, x, 4096)  = 1
 read(0, x, 4096)  = 1
 read(0, x, 4096)  = 1
 read(0, x, 4096)  = 1
 read(0, x, 4096)  = 1
 fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 3), ...}) = 0
 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
 0) = 0x7f3143bab000
 write(1, 120\n, 4120
 )= 4
 ...
 

 This is tremendously inefficient.  It demands a context switch for
 every character.

Inefficiency isn't an issue when you generate one byte a second. If data
were generated at a brisker pace, read(0, ..., 4096) could get more
bytes at a time. Notice that even if the Python code requests 5 bytes,
CPython requests up to 4096 bytes in a single read.


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


[issue22675] typo in argparse.py

2014-10-20 Thread Ricordisamoa

New submission from Ricordisamoa:

It should be no help instead of ho nelp.

--
components: Library (Lib)
files: typo.patch
keywords: patch
messages: 229714
nosy: Ricordisamoa
priority: normal
severity: normal
status: open
title: typo in argparse.py
type: enhancement
Added file: http://bugs.python.org/file36976/typo.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22675
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22675] typo in argparse.py

2014-10-20 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 550de59a4c6d by Georg Brandl in branch '3.4':
Closes #22675: fix typo.
https://hg.python.org/cpython/rev/550de59a4c6d

--
nosy: +python-dev
resolution:  - fixed
stage:  - resolved
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22675
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22675] typo in argparse.py

2014-10-20 Thread Ricordisamoa

Ricordisamoa added the comment:

AFAICT, this also applies to previous versions.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22675
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22674] strsignal() missing from signal module

2014-10-20 Thread Georg Brandl

Georg Brandl added the comment:

Is it possible to determine the range of signal numbers?  Otherwise it would be 
a guessing game where to stop querying when filling up the dictionary.

A problem is also that if the signal number is not valid, the return value of 
strsignal() is unspecified, *and* there is no way to check for this situation 
because no errors are defined.

--
nosy: +georg.brandl

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22674
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22675] typo in argparse.py

2014-10-20 Thread Georg Brandl

Georg Brandl added the comment:

Yes, but those are no longer maintained. It's not a critical bug :)

--
nosy: +georg.brandl

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22675
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17401] io.FileIO closefd parameter is not documented nor shown in repr

2014-10-20 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

FileIO repr now looks confusing:

 sys.stdout.buffer.raw
_io.FileIO name='stdout' mode='wb' closefd='0'

The closefd attribute is not a string '0' or '1', it is boolean value True or 
False. Here is a patch which fixes a repr.

And I think that documentation part of the patch should be backported.

--
nosy: +serhiy.storchaka
resolution: fixed - 
stage:  - patch review
status: closed - open
versions: +Python 3.5 -Python 3.2, Python 3.3
Added file: http://bugs.python.org/file36977/io_fileio_repr_closefd.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17401
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17401] io.FileIO closefd parameter is not documented nor shown in repr

2014-10-20 Thread Robert Collins

Robert Collins added the comment:

Yeah thats nicer. I'll apply that later unless you can.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17401
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12067] Doc: remove errors about mixed-type comparisons.

2014-10-20 Thread Andy Maier

Andy Maier added the comment:

I have posted v12 of the patch, which addresses all comments since v11.

This Python 3.4 patch can be applied to the default (3.5 dev) branch as well.

I will start working on a similar patch for Python 2.7 now.

--
Added file: 
http://bugs.python.org/file36978/issue12067-expressions-py34_v12.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12067
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17401] io.FileIO closefd parameter is not documented nor shown in repr

2014-10-20 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

May be include closefd in the repr only when it is False? By default closefd is 
True and in common case the repr will be more compact.

--
Added file: http://bugs.python.org/file36979/io_fileio_repr_closefd_2.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17401
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22676] _pickle.c

2014-10-20 Thread kbengine

New submission from kbengine:

I have an application, the use of Python3.2.3 development.
When I upgrade to Python3.4.2, found a problem.

I have an extended xxx.c (c-python) module, I call pickle to serialize and 
deserialize, _pickle.c calls the whichmodule to look for this module, The final 
will be to find the module from sys.modules.

But probably there are 200 elements in sys.modules, Use the obj = getattribute 
(module, global_name, allow_qualname) to try to get the object:

static PyObject *
getattribute(PyObject *obj, PyObject *name, int allow_qualname) {
...
...
...

tmp = PyObject_GetAttr(obj, subpath);
Py_DECREF(obj);
 
// There will be hundreds of times to return to NULL
// There will be hundreds of times calls PyErr_Format   
// (PyExc_AttributeError, Can't get attribute%R on%R , name, obj);
// This process will lead to hundreds of calls to moduleobject.c-
// module_repr(PyModuleObject *m).

// So I frequently call pickle.dumps CPU consumption sharply.

if (tmp == NULL) {
if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
PyErr_Clear();


PyErr_Format(PyExc_AttributeError,
 Can't get attribute %R on %R, name, obj);
}
Py_DECREF(dotted_path);
return NULL;
}
   ...
   ...
}

--
   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
  3150.0010.0000.0040.000 frozen 
importlib._bootstrap:690(_module_repr)




I went wrong?
Look forward to answer, thanks!

--
components: Extension Modules
files: 20141020193031.jpg
messages: 229723
nosy: kbengine
priority: normal
severity: normal
status: open
title: _pickle.c
type: performance
versions: Python 3.4
Added file: http://bugs.python.org/file36980/20141020193031.jpg

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22676
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22677] icon not loaded

2014-10-20 Thread Ahmad El-Komey

New submission from Ahmad El-Komey:

Versions 2.7.7 and 2.7.8 (with both builds, 86 and 64 builds) have some strange 
things that is different from other versions:
1. The tk icon of the IDLE is not loaded. The icon loaded is as this one: 
Python27\Lib\idlelib\Icons\idle.ico
and it should be like the one found in Python27\Lib\idlelib\Icons\tk.gif

2. I cannot pin a shortcut to the program! This is not the case with other 
python versions.

--
components: IDLE, Installation, Windows
messages: 229724
nosy: Ahmad.El-Komey, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: icon not loaded
type: behavior
versions: Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22677
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22677] icon not loaded

2014-10-20 Thread Zachary Ware

Changes by Zachary Ware zachary.w...@gmail.com:


--
nosy: +terry.reedy

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22677
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22676] _pickle.c

2014-10-20 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
nosy: +alexandre.vassalotti, pitrou

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22676
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22677] IDLE: icon not loaded

2014-10-20 Thread STINNER Victor

Changes by STINNER Victor victor.stin...@gmail.com:


--
title: icon not loaded - IDLE: icon not loaded

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22677
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22676] _pickle.c

2014-10-20 Thread STINNER Victor

Changes by STINNER Victor victor.stin...@gmail.com:


--
nosy: +haypo

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22676
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22677] IDLE: icon not loaded

2014-10-20 Thread Ahmad El-Komey

Ahmad El-Komey added the comment:

EDIT:
Regarding the icon, I found that this is not an issue. In fact, this is the new 
icon starting from version 2.7.7 (The same goes for 3.4.2. Not sure of previous 
versions)

Regarding the pin to taskbar: After uninstalling Python 3.3 and installing 
Python 3.4.2, I can pin python 2.7.8 to the taskbar. I really have no idea why.

That is all.

--
resolution:  - not a bug
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22677
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22674] strsignal() missing from signal module

2014-10-20 Thread STINNER Victor

STINNER Victor added the comment:

I don't think that a strsignal() is required, signals now have a name attribute!

Python 3.5.0a0 (default:07ae7bc06af0, Oct 16 2014, 09:46:01) 
 import signal
 signal.SIGINT
Signals.SIGINT: 2
 signal.SIGINT.name
'SIGINT'

--
nosy: +haypo

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22674
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17401] io.FileIO closefd parameter is not documented nor shown in repr

2014-10-20 Thread Arfrever Frehtes Taifersar Arahesis

Changes by Arfrever Frehtes Taifersar Arahesis arfrever@gmail.com:


--
nosy: +Arfrever

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17401
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22673] document the special features (eg: fdclose=False) of the standard streams

2014-10-20 Thread Arfrever Frehtes Taifersar Arahesis

Changes by Arfrever Frehtes Taifersar Arahesis arfrever@gmail.com:


--
nosy: +Arfrever

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22673
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15989] Possible integer overflow of PyLong_AsLong() results

2014-10-20 Thread Arfrever Frehtes Taifersar Arahesis

Changes by Arfrever Frehtes Taifersar Arahesis arfrever@gmail.com:


--
nosy: +Arfrever

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15989
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22660] Review ssl docs for security recommendations

2014-10-20 Thread Arfrever Frehtes Taifersar Arahesis

Changes by Arfrever Frehtes Taifersar Arahesis arfrever@gmail.com:


--
nosy: +Arfrever

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22660
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22676] Creating the string representation of a module is slower

2014-10-20 Thread Brett Cannon

Brett Cannon added the comment:

In Python 3.3 the import machinery changed to use importlib. This means the 
code to create the representation of a module now calls into Python code (the 
`frozen importlib._bootstrap:690(_module_repr)` you're seeing).

But my question is why are you not calling PyObject_HasAttr() before calling 
PyObject_GetAttr()? Exceptions may be relatively cheap but they are not free.

--
nosy: +brett.cannon
status: open - pending
title: _pickle.c - Creating the string representation of a module is slower

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22676
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22445] Memoryviews require more strict contiguous checks then necessary

2014-10-20 Thread Sebastian Berg

Sebastian Berg added the comment:

Antoine, sounds good to me, I don't mind this being in python rather sooner 
then later, for NumPy itself it does not matter I think. I just wanted to warn 
that there were problems when we first tried to switch in NumPy, which, if I 
remember correctly, is now maybe 2 years ago (in a dev version), though.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22445
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22678] An OSError subclass for no space left on device would be nice

2014-10-20 Thread Mathieu Bridon

New submission from Mathieu Bridon:

I found myself writing the following code the other day:

try:
os.mkdir(path)

except PermissionError:
do_something()

except FileExistsError:
do_something_else()

except FileNotFoundError:
do_yet_another_thing()

except OSError as e:
import errno
if e.errno == errno.ENOSPC:
and_do_one_more_different_thing()

else:
raise e

The OSError subclasses in Python 3 are amazing, I love them.

I just wish there'd be more of them. :)

--
components: Library (Lib)
messages: 229729
nosy: bochecha
priority: normal
severity: normal
status: open
title: An OSError subclass for no space left on device would be nice
versions: Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22678
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22678] An OSError subclass for no space left on device would be nice

2014-10-20 Thread Mathieu Bridon

Changes by Mathieu Bridon boche...@daitauha.fr:


--
keywords: +patch
Added file: http://bugs.python.org/file36981/0001-New-NoSpaceError.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22678
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22678] An OSError subclass for no space left on device would be nice

2014-10-20 Thread Mathieu Bridon

Changes by Mathieu Bridon boche...@daitauha.fr:


Added file: http://bugs.python.org/file36982/0002-Use-the-new-NoSpaceError.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22678
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22679] Add encodings of supported in glibc locales

2014-10-20 Thread Serhiy Storchaka

New submission from Serhiy Storchaka:

There are 6 encodings used in supported by glibc locales:

ARMSCII-8 - Armenian encoding
EUC-TW - Taiwan encoding in EUC family
GEORGIAN-PS - Georgian encoding
KOI8-T - Tajik encoding in KOI family
RK1048 - Kazakh variation of CP1251
TCVN5712-1 - Vietnam encoding

All these encodings are rare nowadays, but the fact that they are supported as 
encoding of official glibc locales means that they were used in some places in 
some time and there are some documents in these encodings. May be they are used 
even nowadays. I think it is worth to add support of all this encodings in 
Python.

This is a meta-issue. There are requests for support of GEORGIAN-PS 
(issue19459) and TCVN5712-1 (issue21081).

--
components: Library (Lib)
messages: 229730
nosy: haypo, lemburg, loewis, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Add encodings of supported in glibc locales
type: enhancement
versions: Python 3.5

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22679
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22679] Add encodings of supported in glibc locales

2014-10-20 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
dependencies: +Python does not support the GEORGIAN-PS charset, missing 
vietnamese codec TCVN 5712:1993 in Python

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22679
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22680] unittest discovery is fragile

2014-10-20 Thread Antoine Pitrou

New submission from Antoine Pitrou:

I just got the following traceback when trying discover without 3.5. It runs 
fine under 3.4...

$ ~/cpython/default/python -m unittest discover -v
Traceback (most recent call last):
  File /home/antoine/cpython/default/Lib/runpy.py, line 170, in 
_run_module_as_main
__main__, mod_spec)
  File /home/antoine/cpython/default/Lib/runpy.py, line 85, in _run_code
exec(code, run_globals)
  File /home/antoine/cpython/default/Lib/unittest/__main__.py, line 18, in 
module
main(module=None)
  File /home/antoine/cpython/default/Lib/unittest/main.py, line 93, in 
__init__
self.runTests()
  File /home/antoine/cpython/default/Lib/unittest/main.py, line 244, in 
runTests
self.result = testRunner.run(self.test)
  File /home/antoine/cpython/default/Lib/unittest/runner.py, line 168, in run
test(result)
  File /home/antoine/cpython/default/Lib/unittest/suite.py, line 87, in 
__call__
return self.run(*args, **kwds)
  File /home/antoine/cpython/default/Lib/unittest/suite.py, line 125, in run
test(result)
  File /home/antoine/cpython/default/Lib/unittest/suite.py, line 87, in 
__call__
return self.run(*args, **kwds)
  File /home/antoine/cpython/default/Lib/unittest/suite.py, line 125, in run
test(result)
  File /home/antoine/cpython/default/Lib/unittest/suite.py, line 87, in 
__call__
return self.run(*args, **kwds)
  File /home/antoine/cpython/default/Lib/unittest/suite.py, line 125, in run
test(result)
  File /home/antoine/cpython/default/Lib/unittest/case.py, line 625, in 
__call__
return self.run(*args, **kwds)
  File /home/antoine/cpython/default/Lib/unittest/case.py, line 553, in run
result.startTest(self)
  File /home/antoine/cpython/default/Lib/unittest/runner.py, line 54, in 
startTest
self.stream.write(self.getDescription(test))
  File /home/antoine/cpython/default/Lib/unittest/runner.py, line 47, in 
getDescription
return '\n'.join((str(test), doc_first_line))
  File /home/antoine/cpython/default/Lib/unittest/case.py, line 1354, in 
__str__
self._testFunc.__name__)
AttributeError: 'str' object has no attribute '__name__'

--
components: Library (Lib)
messages: 229731
nosy: ezio.melotti, michael.foord, pitrou, rbcollins
priority: normal
severity: normal
stage: needs patch
status: open
title: unittest discovery is fragile
type: behavior
versions: Python 3.5

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22680
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22680] unittest discovery is fragile

2014-10-20 Thread Michael Foord

Michael Foord added the comment:

I assume you mean you get the error *with* 3.5 (not without). Does this 
happen *every time* (i.e. is it trivially reproducible) - or can you provide a 
repro?

This is regression that I would *assume* (a totally lazy assumption) introduced 
by the new error handling code.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22680
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22680] unittest discovery is fragile

2014-10-20 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 I assume you mean you get the error *with* 3.5 (not without).

Yes, sorry :-)

 Does this happen *every time* (i.e. is it trivially reproducible)

It happens with the llvmlite repository: https://github.com/numba/llvmlite
Since using it requires some compiling, I could try to investigate myself if 
you tell me what to look for.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22680
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22680] unittest discovery is fragile

2014-10-20 Thread Michael Foord

Michael Foord added the comment:

As _testFunc is a string and shouldn't be, I'd be very interested to know 
*what* the string is. That may give us a clue as to where it has come from. (So 
a try...except...raise that also prints that value would be a good first step.)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22680
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22680] unittest discovery is fragile

2014-10-20 Thread Antoine Pitrou

Antoine Pitrou added the comment:

testFunc contains runTest (!).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22680
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21081] missing vietnamese codec TCVN 5712:1993 in Python

2014-10-20 Thread Jean Christophe André

Jean Christophe André added the comment:

A note to inform about my progress. (I had a long period without free time at 
hand)

While seeking (again) official documents on the topic, I mainly found a lot of 
non-official ones, but some are notorious enough to use them as references.

I am now in the process of creating the requested patch. I am currently 
studying the proper way to do it. I expect to get it ready this weekend, in the 
hope to have it accepted for Python 3.5.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21081
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22680] unittest discovery is fragile

2014-10-20 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Ok, apparently it's because I have from unittest import * somewhere.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22680
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22674] strsignal() missing from signal module

2014-10-20 Thread Georg Brandl

Georg Brandl added the comment:

Nice. However, strsignal() returns not just SIGINT, but Interrupted etc.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22674
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22680] unittest discovery is fragile

2014-10-20 Thread Barry A. Warsaw

Changes by Barry A. Warsaw ba...@python.org:


--
nosy: +barry

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22680
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22681] Add support of KOI8-T encoding

2014-10-20 Thread Serhiy Storchaka

New submission from Serhiy Storchaka:

KOI8-T is Tajik encoding partially compatible with KOI8-R. This is default 
encoding of Tajik locale tg_TJ in glibc (but in X11 locale.alias file it is 
KOI8-C, issue20087).

Proposed patch adds support for this encoding. I have not found official 
mapping of KOI8-T and have used a table from Apple's implementation of 
libiconv. It matches a table in Wikipedia [2] and GNU iconv.

[1] 
http://www.opensource.apple.com/source/libiconv/libiconv-4/libiconv/tests/KOI8-T.TXT
[2] https://ru.wikipedia.org/wiki/КОИ-8 (Russian)

--
components: Library (Lib)
messages: 229739
nosy: serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Add support of KOI8-T encoding
type: enhancement
versions: Python 3.5

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22681
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22680] unittest discovery is fragile

2014-10-20 Thread Ethan Furman

Changes by Ethan Furman et...@stoneleaf.us:


--
nosy: +ethan.furman

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22680
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >