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  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 
wrote:

> On Sun, Oct 19, 2014 at 10:19 AM, Mark Lawrence 
> 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 
> >>  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  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()>> 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
, 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  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 ,
> 
>  Noble Bell  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  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  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  wrote:
> On Mon, Oct 20, 2014 at 9:54 AM, Simon Kennedy  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 
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 
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  wrote:

> On Mon, Oct 20, 2014 at 11:54 AM, Ian Kelly  wrote:
> > On Mon, Oct 20, 2014 at 9:54 AM, Simon Kennedy 
> 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
 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 ', '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 
 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 
 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 
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
 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 
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
 wrote:

>On 20/10/2014 20:49, Seymore4Head wrote:
>> On Mon, 20 Oct 2014 20:40:18 +0100, MRAB 
>> 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 
wrote:

>On Mon, Oct 20, 2014 at 1:49 PM, 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?
>
>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 responsibl

Re: Building lists

2014-10-20 Thread Ian Kelly
On Mon, Oct 20, 2014 at 2:23 PM, Seymore4Head
 wrote:
> On Mon, 20 Oct 2014 13:58:46 -0600, Ian Kelly 
> wrote:
>
>>On Mon, Oct 20, 2014 at 1:49 PM, 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?
>>
>>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  Seymore4Head 
 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 
wrote:


On Mon, Oct 20, 2014 at 1:49 PM, 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?


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 
wrote:

>On Mon, Oct 20, 2014 at 2:23 PM, Seymore4Head
> wrote:
>> On Mon, 20 Oct 2014 13:58:46 -0600, Ian Kelly 
>> wrote:
>>
>>>On Mon, Oct 20, 2014 at 1:49 PM, 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?
>>>
>>>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
 wrote:

>In  Seymore4Head 
> 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
 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  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
 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  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 ', '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 
>>  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 
>>  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
 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 :

> On Sun, Oct 19, 2014 at 9:45 PM, Marko Rauhamaa  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 :

> ...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 , 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 "", line 1, in 
  File 
"/Users/mynamehere/.continuum/anaconda/envs/py3k/lib/python3.4/site-packages/quaternion/__init__.py",
 line 3, in 
    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 
, 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  wrote:

> I'm modifying an extension written with the c-api to have a datatype of
> quaternions , 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 "", line 1, in 
>   File
> "/Users/mynamehere/.continuum/anaconda/envs/py3k/lib/python3.4/site-packages/quaternion/__init__.py",
> line 3, in 
> 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 , 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  wrote:
> I'm modifying an extension written with the c-api to have a datatype of 
> quaternions , 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 "", line 1, in 
>   File 
> "/Users/mynamehere/.continuum/anaconda/envs/py3k/lib/python3.4/site-packages/quaternion/__init__.py",
>  line 3, in 
> 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 , 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__': , '__package__': None, 'builtins':
, 'orig_import': , '__builtins__': ,
'__name__': '__main__', '__doc__': None, 'debug_import': } {'__spec__': None, '__loader__':
, '__package__': None,
'builtins': , 'orig_import': , '__builtins__': ,
'__name__': '__main__', '__doc__': None, 'debug_import': } 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  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
 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  wrote:
>> I'm modifying an extension written with the c-api to have a datatype of 
>> quaternions , 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 "", line 1, in 
>> File 
>> "/Users/mynamehere/.continuum/anaconda/envs/py3k/lib/python3.4/site-packages/quaternion/__init__.py",
>>  line 3, in 
>> 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 , 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__':  '_frozen_importlib.BuiltinImporter'>, '__package__': None, 'builtins':
> , 'orig_import':  __import__>, '__builtins__': ,
> '__name__': '__main__', '__doc__': None, 'debug_import':  debug_import at 0x7f6096aac9d8>} {'__spec__': None, '__loader__':
> , '__package__': None,
> 'builtins': , 'orig_import':  function __import__>, '__builtins__': ,
> '__name__': '__main__', '__doc__': None, 'debug_import':  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  wrote:
> Dan Stromberg :
>> ...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 ,
> 
> > 
> 
> >  Noble Bell  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 :

> 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


Re: OS X Menubar in Tkinter

2014-10-20 Thread Mark Lawrence

On 21/10/2014 02:34, Noble Bell wrote:


Creating the app with py2app fixed my problem.



I'm pleased to see that you have an answer.  In return 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