Re: Quick Question About Setting Up Pytz

2014-10-18 Thread Rustom Mody
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


Re: Quick Question About Setting Up Pytz

2014-10-18 Thread Chris Angelico
On Sun, Oct 19, 2014 at 1:54 PM, 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.
>
> 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.

That's a rough business to be in... I mean... that's unfortunate.
However, I'd still advise anyone to learn the language itself first,
even if that means a rule like "avoid working with international or
historical time". There are plenty of other things Python can do, even
just with a basic Windows installation.

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


Re: Quick Question About Setting Up Pytz

2014-10-18 Thread Ben Finney
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.

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.

-- 
 \  “Nothing is more sacred than the facts.” —Sam Harris, _The End |
  `\   of Faith_, 2004 |
_o__)  |
Ben Finney

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


Re: Quick Question About Setting Up Pytz

2014-10-18 Thread Ben Finney
ryguy7272  writes:

> So, when I run it, the setup.py text file opens. Nothing runs; nothing
> installs.

You have somehow (either manually, or by answering a question to some
program) associated the ‘.py’ suffix with “Open this file in my text
editor”.

That's fine, but it means that if you don't want to edit the file but
instead want to execute it, you need to *explicitly* start Python:

python /whatever/path/to/setup.py install

> This makes no sense whatsoever.

This is an issue with your operating system, so I would hope you can
learn more about that to distinguish what is causing your frustration
:-)

-- 
 \  “I got an answering machine for my phone. Now when someone |
  `\  calls me up and I'm not home, they get a recording of a busy |
_o__)  signal.” —Steven Wright |
Ben Finney

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


Re: Quick Question About Setting Up Pytz

2014-10-18 Thread Chris Angelico
On Sun, Oct 19, 2014 at 1:44 PM, ryguy7272  wrote:
> I'll probably give it until the end of the year, and start learning Chinese.  
> There's other things I want to do with my time.  I know 10 programming 
> languages.  I thought it would be fun to learn Python, but after 2 months, I 
> still can't run a single line of code.  This language makes no sense 
> whatsoever, and it never does anything that you tell it to do.
>

Try learning Python itself, rather than playing around with extension
packages like pytz. You're having trouble installing add-ons - that's
like saying "Computers are total rubbish, I bought this fancy new ISA
card and I can't make it work!". Start with what you have, and worry
about the extra complexities later.

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


Re: Quick Question About Setting Up Pytz

2014-10-18 Thread ryguy7272
On Saturday, October 18, 2014 3:55:02 PM UTC-4, ryguy7272 wrote:
> I downloaded PYTZ and put it here.
> 
> C:\Python27\pytz
> 
> 
> 
> Now, in the cmd window, I typed this:
> 
> C:\Python27\pytz\setup.py
> 
> 
> 
> A text file opens and nothing else happens.  I thought it was supposed to 
> install the PYTZ library.  
> 
> 
> 
> What am I doing wrong?


Thanks Mark. That makes sense.  I moved the folder to the desktop and I just 
tried that:
C:\Users\Ryan\Desktop\pytz>setup.py install

So, when I run it, the setup.py text file opens.  Nothing runs; nothing 
installs.  This makes no sense whatsoever.  If I tell a program to install 
something, it should install something.  It should not pop open a text file.  

I'll probably give it until the end of the year, and start learning Chinese.  
There's other things I want to do with my time.  I know 10 programming 
languages.  I thought it would be fun to learn Python, but after 2 months, I 
still can't run a single line of code.  This language makes no sense 
whatsoever, and it never does anything that you tell it to do.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Flush stdin

2014-10-18 Thread Dan Stromberg
On Sat, Oct 18, 2014 at 6:34 PM, Dan Stromberg  wrote:
>> Once the "nc" process actually write()s the data to its standard
>> output (i.e. desriptor 1, not the "stdout" FILE*)
> I'm not sure why you're excluding stdout, but even if nc is using
> filedes 1 instead of FILE * stdout, isn't it kind of irrelevant?

On further reflection, isn't it stdio that does the varied buffering,
and filedes 1 that's always unbuffered?  IOW, the OP might wish nc was
using 1, but it probably can't be given what they're seeing.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Flush stdin

2014-10-18 Thread Dan Stromberg
On Sat, Oct 18, 2014 at 6:11 PM, Nobody  wrote:
> On Sat, 18 Oct 2014 12:32:07 -0500, Tim Chase wrote:
>
>> On 2014-10-18 17:55, Nobody wrote:
>>> On Fri, 17 Oct 2014 12:38:54 +0100, Empty Account wrote:
>>>
>>> > I am using netcat to listen to a port and python to read stdin and
>>> > print to the console.
>>> >
>>> > nc -l 2003 | python print_metrics.py
>>> >
>>> > sys.stdin.flush() doesn’t seem to flush stdin,
>>>
>>> You can't "flush" an input stream.
>>
>> You can't flush it, but you can make it unbuffered.  You can either force
>> python to use unbuffered stdio:
>
> [snipped]
>
> None of this helps in any way, as it's not the behaviour of the Python
> script which is causing the problem, but that "nc" is (probably) buffering
> its output, so the data isn't passed to the OS (let alone to the Python
> script) in a timely manner.

Agreed.

> Once the "nc" process actually write()s the data to its standard
> output (i.e. desriptor 1, not the "stdout" FILE*)
I'm not sure why you're excluding stdout, but even if nc is using
filedes 1 instead of FILE * stdout, isn't it kind of irrelevant?

> it will be available to
> the Python script immediately thereafter without requiring any low-level
> tweaks.
Which, on a pipe, generally means either the buffer filled and needed
to be passed along to make room, or the process exited.

I'd probably rewrite just enough nc in Python to make it so you don't
need to depend on a pipe (example:
http://stromberg.dnsalias.org/~strombrg/pnetcat.html), but if you're
on *ix you could try
http://ftp.sunet.se/pub/usenet/ftp.uu.net/comp.sources.unix/volume23/pty/
in an effort to persuade nc to think that it's on a tty and hence
should output line buffered data instead of block buffered - despite
being on a pipe in reality.

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


Re: Flush stdin

2014-10-18 Thread Chris Angelico
On Fri, Oct 17, 2014 at 10:38 PM, Empty Account  wrote:
> I am using netcat to listen to a port and python to read stdin and print to
> the console.
>
> nc -l 2003 | python print_metrics.py

After lengthy discussion about what it means to flush stdin, I think
it's high time someone asked the question: Why not skip nc altogether,
and have your Python program do its own socket work? Then you don't
have to worry about stream flushing at all.

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


Re: Flush stdin

2014-10-18 Thread Nobody
On Sat, 18 Oct 2014 12:32:07 -0500, Tim Chase wrote:

> On 2014-10-18 17:55, Nobody wrote:
>> On Fri, 17 Oct 2014 12:38:54 +0100, Empty Account wrote:
>> 
>> > I am using netcat to listen to a port and python to read stdin and
>> > print to the console.
>> > 
>> > nc -l 2003 | python print_metrics.py
>> > 
>> > sys.stdin.flush() doesn’t seem to flush stdin,
>> 
>> You can't "flush" an input stream.
> 
> You can't flush it, but you can make it unbuffered.  You can either force
> python to use unbuffered stdio:

[snipped]

None of this helps in any way, as it's not the behaviour of the Python
script which is causing the problem, but that "nc" is (probably) buffering
its output, so the data isn't passed to the OS (let alone to the Python
script) in a timely manner.

Once the "nc" process actually write()s the data to its standard
output (i.e. desriptor 1, not the "stdout" FILE*), it will be available to
the Python script immediately thereafter without requiring any low-level
tweaks.

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


Re: Flush stdin

2014-10-18 Thread Terry Reedy

On 10/18/2014 5:01 PM, Cameron Simpson wrote:

On 18Oct2014 17:55, Nobody  wrote:

On Fri, 17 Oct 2014 12:38:54 +0100, Empty Account wrote:

I am using netcat to listen to a port and python to read stdin and print
to the console.

nc -l 2003 | python print_metrics.py

sys.stdin.flush() doesn’t seem to flush stdin,


You can't "flush" an input stream.



Sure you can.


You are collectively confusing three different meaning of 'flush'. 
Python and its docs are the best authority on what python can and cannot 
do.  One can "call .flush() on an imput stream" (meaning 1).


>>> import sys
>>> sys.stdin.flush()
>>>

However, one cannot "empty the steam buffer by calling .flush()" 
(meaning 2).


" class IOBase
...
flush()
Flush the write buffers of the stream if applicable. This does 
nothing for read-only and non-blocking streams."



Most streams are read through an API which buffers. That
buffer can be discarded.


But one can "empty and discard the buffer" (meaning 3) with
stream.read()

And, of course, an 'input stream' 'down here' is an 'output stream' 'up 
there, where ever' and one can 'flush' pending output into the stream so 
that it can be read here.


--
Terry Jan Reedy


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


Re: Flush stdin

2014-10-18 Thread Cameron Simpson

On 18Oct2014 17:55, Nobody  wrote:

On Fri, 17 Oct 2014 12:38:54 +0100, Empty Account wrote:

I am using netcat to listen to a port and python to read stdin and print
to the console.

nc -l 2003 | python print_metrics.py

sys.stdin.flush() doesn’t seem to flush stdin,


You can't "flush" an input stream.


Sure you can. Most streams are read through an API which buffers. That buffer 
can be discarded.


I'm not sure it is what the OP needs, but it is not a nonsensical idea.

Cheers,
Cameron Simpson 

I've seen things you people wouldn't believe.  Attack ships on fire off the
shoulder of Orion. I've watched C-beams glitter in the dark near the
Tannhauser Gate.  All these memories will be lost in time, like tears in rain.
- Roy Baty, _Blade Runner_
--
https://mail.python.org/mailman/listinfo/python-list


Re: Quick Question About Setting Up Pytz

2014-10-18 Thread Mark Lawrence

On 18/10/2014 20:54, ryguy7272 wrote:

I downloaded PYTZ and put it here.
C:\Python27\pytz

Now, in the cmd window, I typed this:
C:\Python27\pytz\setup.py

A text file opens and nothing else happens.  I thought it was supposed to 
install the PYTZ library.

What am I doing wrong?



You will end up confusing yourself very quickly if you insist on placing 
files in c:\Python27.  Please put them anywhere except that spot, say in 
downloads or on the desktop.  Let's assume your desktop is here 
c:\Users\ryguy7272\Desktop.  Open a cmd window then


cd c:\Users\ryguy7272\Desktop
setup.py install

should work if and only if you have the file types and file associations 
correctly set, please see 
https://docs.python.org/2/using/windows.html#executing-scripts


Better still take the hard work out of it by getting pip by following 
the instructions here http://pip.readthedocs.org/en/latest/installing.html


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


Question about PANDAS

2014-10-18 Thread ryguy7272
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

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.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Quick Question About Setting Up Pytz

2014-10-18 Thread Joel Goldstick
On Sat, Oct 18, 2014 at 3:54 PM, ryguy7272  wrote:
> I downloaded PYTZ and put it here.
> C:\Python27\pytz
>
> Now, in the cmd window, I typed this:
> C:\Python27\pytz\setup.py
>
> A text file opens and nothing else happens.  I thought it was supposed to 
> install the PYTZ library.
>
> What am I doing wrong?
> --
> https://mail.python.org/mailman/listinfo/python-list

have you tried:

python c:\Python27/pytz/setup.py




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


Quick Question About Setting Up Pytz

2014-10-18 Thread ryguy7272
I downloaded PYTZ and put it here.
C:\Python27\pytz

Now, in the cmd window, I typed this:
C:\Python27\pytz\setup.py

A text file opens and nothing else happens.  I thought it was supposed to 
install the PYTZ library.  

What am I doing wrong?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Flush stdin

2014-10-18 Thread MRAB

On 2014-10-18 17:55, Nobody wrote:

On Fri, 17 Oct 2014 12:38:54 +0100, Empty Account wrote:


I am using netcat to listen to a port and python to read stdin and print
to the console.

nc -l 2003 | python print_metrics.py

sys.stdin.flush() doesn’t seem to flush stdin,


You can't "flush" an input stream.


[snip]

Flushing an input stream means (or could mean) discarding any data
that's currently in the buffer.

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


Re: Flush stdin

2014-10-18 Thread Tim Chase
On 2014-10-18 17:55, Nobody wrote:
> On Fri, 17 Oct 2014 12:38:54 +0100, Empty Account wrote:
> 
> > I am using netcat to listen to a port and python to read stdin
> > and print to the console.
> > 
> > nc -l 2003 | python print_metrics.py
> > 
> > sys.stdin.flush() doesn’t seem to flush stdin,
> 
> You can't "flush" an input stream.

You can't flush it, but you can make it unbuffered.  You can either
force python to use unbuffered stdio:

  python -u myfile.py

or you can get an unbuffered handle to the file

 import os, sys
 buffer_size = 1
 new_stdin = os.fdopen(sys.stdin.fileno(), 'r', buffer_size)
 for c in new_stdin:
   do_something(c)

though based on my reading, the first method works with both Py2
and Py3k while the second method doesn't reliably work in Py3k.

-tkc




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


Re: Flush stdin

2014-10-18 Thread Nobody
On Fri, 17 Oct 2014 12:38:54 +0100, Empty Account wrote:

> I am using netcat to listen to a port and python to read stdin and print
> to the console.
> 
> nc -l 2003 | python print_metrics.py
> 
> sys.stdin.flush() doesn’t seem to flush stdin,

You can't "flush" an input stream.

> so I am using the termios module.

> I am receiving this exception
> termios.error: (25, 'Inappropriate ioctl for device')

termios only works on terminals, not pipes.

It's a safe bet that your problem is that "nc" isn't flushing its stdout
after each line (this is the default behaviour for stdio streams which
don't correspond to a terminal).

Check whether "nc" has a flag to line-buffer its output. If it doesn't,
the simplest solution is probably to write a Python script which creates a
pseudo-tty (using the "pty" module) and executes "nc" with its stdout
associated with the pty.

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


Re: your mail

2014-10-18 Thread Peter Otten
Alain Ketterlin wrote:

> Terry Reedy  writes:
> 
>> On 10/17/2014 6:43 AM, Cameron Simpson wrote:
>>> On 17Oct2014 11:45, Dhananjay  wrote:
>>
 2.1576318858 -1.8651195165 4.2333428278
 ...
 (total of 200 lines)

 Columns 1,2,3 corresponds to x,y,z axis data points.
>>
>>>for line in open('flooding-psiphi.dat','r'):
>>>line = line.split()
>>>xs.append(float(line[0]))
>>>ys.append(float(line[1]))
>>>zs.append(float(line[2]))
>>
>> A further refinement:
>>for line in open('flooding-psiphi.dat','r'):
>>x, y, z = map(float, line.split())
>>xs.append(x)
>>ys.append(y)
>>zs.append(z)
> 
> Or even:
> 
> xs,ys,zs = zip(*[ map(float,line.split())
>   for line in open('flooding-psiphi.dat','r') ])
> 
> You get tuples, though. Use map(list,zip(...)) if you need lists. Easy
> to update when you move to 4D data...

Given the context (the script uses numpy) there is another option:

xs, ys, zs = numpy.loadtxt('flooding-psiphi.dat').T

There may also be a way to feed the array to matplotlib without breaking it 
into the three columns...

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


Re: pyserial on freebsd 10.10 i386 [SOLVED]

2014-10-18 Thread Nagy László Zsolt
The port parameter of serial.Serial should be /dev/ttyu0 instead of 
COM1, and /dev/ttyu1 instead of COM2.


Strangely, pyserial will accept the number 0, but then it tries to open 
a device that exists on Linux only...


Anyway, problem solved.
--
https://mail.python.org/mailman/listinfo/python-list


Re: your mail

2014-10-18 Thread Alain Ketterlin
Terry Reedy  writes:

> On 10/17/2014 6:43 AM, Cameron Simpson wrote:
>> On 17Oct2014 11:45, Dhananjay  wrote:
>
>>> 2.1576318858 -1.8651195165 4.2333428278
>>> ...
>>> (total of 200 lines)
>>>
>>> Columns 1,2,3 corresponds to x,y,z axis data points.
>
>>for line in open('flooding-psiphi.dat','r'):
>>line = line.split()
>>xs.append(float(line[0]))
>>ys.append(float(line[1]))
>>zs.append(float(line[2]))
>
> A further refinement:
>for line in open('flooding-psiphi.dat','r'):
>x, y, z = map(float, line.split())
>xs.append(x)
>ys.append(y)
>zs.append(z)

Or even:

xs,ys,zs = zip(*[ map(float,line.split())
  for line in open('flooding-psiphi.dat','r') ])

You get tuples, though. Use map(list,zip(...)) if you need lists. Easy
to update when you move to 4D data...

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


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

2014-10-18 Thread Steven D'Aprano
Simon Kennedy wrote:

> On Wednesday, 15 October 2014 20:31:15 UTC+1, Ian  wrote:
>> I agree. I very rarely use blank lines inside functions. As I see it,
>> if you feel you need a blank line for separation within a function,
>> that's an indication your function is overly complex and should be
>> broken up.
> 
> Whereas I feel that if I wanted to write code which looked like that I'd
> have learnt/learned Perl ;-)

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"

Are you suggesting that Perl functions tend to be too small? What do you
consider "too small"?


-- 
Steven

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


pyserial on freebsd 10.10 i386

2014-10-18 Thread Nagy László Zsolt


I'm trying to open a serial port with pyserial on a Compaq Deskpro EN 
machine. Operating system is FreeBSD 10.10 RELEASE, i386.


root@merleg:~ # kldload scc
root@merleg:~ # python2.7 -m serial.tools.list_ports
no ports found
root@merleg:~ # whoami
root


Here are all the devices:

root@merleg:~ # ls /dev

acpicttyklogstdin   ttyva
ad0 cuau0   kmemstdout  ttyvb
ad0p1   cuau0.init  log sysmousettyvc
ad0p2   cuau0.lock  lpt0ttyu0   ttyvd
ad0p3   cuau1   lpt0.ctlttyu0.init  ttyve
ada0cuau1.init  mdctl   ttyu0.lock  ttyvf
ada0p1  cuau1.lock  mem ttyu1   ufssuspend
ada0p2  devctl  midistatttyu1.init  ugen0.1
ada0p3  devstat mixer0  ttyu1.lock  ugen0.2
agpgart fd  nfslock ttyv0   uhid0
apm fd0 nullttyv1   ukbd0
apmctl  fidopass0   ttyv2   urandom
atkbd0  geom.ctlpass1   ttyv3   usb
audit   gptid   pci ttyv4   usbctl
bpf io  ppi0ttyv5   xpt0
bpf0kbd0pts ttyv6   zero
cd0 kbd1random  ttyv7
console kbd2sndstat ttyv8
consolectl  kbdmux0 stderr  ttyv9


And here is what I see in dmesg:

root@merleg:~ # dmesg | grep uart

uart0: <16550 or compatible> port 0x3f8-0x3ff irq 4 flags 0x10 on acpi0

uart1: <16550 or compatible> port 0x2f8-0x2ff irq 3 on acpi0

Obviously the question is: how do I open the COM port from pyserial on 
this machine?




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


Re: Sqlite3 help

2014-10-18 Thread Sibylle Koczian

Am 14.10.2014 15:36, schrieb Chuck:

I am building a simple podcast program where I download all the data from a 
feed with feedparser and store the data in sqlite3.  I am spanking new to 
sqlite and database programming.  Should I create the database in the __init__ 
method of my class, or is that a bad idea.  I haven't done any designing that 
included databases.

Thanks!
Chuck

When I first answered this question, I sent the answer erroneously to 
the OP and not to the list. So here it is again.


On Tue, Oct 14, 2014 at 1:19 PM, Sibylle Koczian wrote:
>
> As I don't know anything at all about podcasts and feeds, I'll just
> answer your question about creating the database in the __init__
> method of your class:
>
> That would destroy the existing database and create a new one without
> any data. If you don't want to keep data from former runs of your
> application, this wouldn't be necessary, because you could just
> delete the data and keep the database. But most probably you want to
> keep your data and add to it. In this case, you certainly don't want
> to create a new database.
>
> The __init__ method of your class might be the right place to open
> the database, though.
>
> You know that the documentation for the sqlite3 module is part of the
> Python documentation? It contains links to the SQLite web page and to
> a website with beginner information about SQL itself. So that should
> help to get you started.

Am 15.10.2014 18:51, schrieb Chuck Johnson:
>
> I was thinking that I could fix that by using ' ' ' CREATE TABLE IF
> NOT EXISTS ' ' '   Should I make the sqlite3.connect() command a
> global variable?  I am not sure about how to design this properly.
>
That should work. I wouldn't make the connection a global variable. Use 
it as a parameter for every function that needs it. Roughly like this:


import sqlite3
# other imports as needed

def one_of_my_functions(myconn, my_other_parameters):
mycurs = myconn.cursor()
try:
# do things with mycurs and my_other_parameters
finally:
mycurs.close()
myconn.commit()

# more of the same ...

def main():
conn = sqlite3.connect('path/to/my/database')
try:
one_of_my_functions(conn, params)
# more of the same
finally:
conn.close()

if __name__ == "__main__":
main()


Or, if your program gets bigger, you might start and stop a connection 
inside a function instead of keeping one connection open for all of the 
application.


HTH
Sibylle




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


Re: Extract Indices of Numpy Array Based on Given Bit Information

2014-10-18 Thread Artur Bercik
On Sat, Oct 18, 2014 at 4:10 PM, Chris Angelico  wrote:

> On Sat, Oct 18, 2014 at 6:02 PM, Artur Bercik  wrote:
> > So, the  Bit No. 2-5 for the following case is '1101', right?
> >
> > 1073741877: 1110101
> >
> >  If my required bit combination for Bit No. 2-5 is '1011', then the above
> > number (1073741877) is not chosen, right??
> >
> > Look forward to know your confirmation.
>
> (Side point: Please don't top-post. The convention on this mailing
> list, and most other technical mailing lists, is what's sometimes
> called "interleaved style"; you trim the quoted text to what's needed
> for context, and put your text underneath what you're referring to.
> See https://en.wikipedia.org/wiki/Posting_style#Interleaved_style for
> more info.)
>
> >>> 1073741877&60
> 52
> >>> bin(52)
> '0b110100'
>
> Everything I've written with the triple-angle-bracket marker can be
> typed in at the Python prompt, and you'll see exactly what it does. In
> this case, you can see that you're absolutely right: 1073741877 has
> 1101 in those positions, so if you're looking for 1011, it won't
> match:
>
> >>> 0b101100
> 44
>
> However, 1073741869 would:
>
> >>> 1073741869&60
> 44
>
> The way to test would be something like this:
>
> >>> (1073741877 & 0b00) == 0b101100
> False
> >>> (1073741869 & 0b00) == 0b101100
> True
>

Thank you very much Chris Angelico, I have come to know it.





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


Re: Extract Indices of Numpy Array Based on Given Bit Information

2014-10-18 Thread Artur Bercik
So, the  Bit No. 2-5 for the following case is '1101', right?

1073741877: 1110101

 If my required bit combination for Bit No. 2-5 is '1011', then the above
number (1073741877) is not chosen, right??

Look forward to know your confirmation.

On Sat, Oct 18, 2014 at 3:50 PM, Chris Angelico  wrote:

> On Sat, Oct 18, 2014 at 5:42 PM, Artur Bercik  wrote:
> > I got some sense, but could not imagine if required Bit No. 2–5, and  Bit
> > Combination .
> >
> > I hope example with the new case would make me more sense.
> >
>
> Just write the number in binary, with the bits you're interested in
> set to 1, and everything else 0:
>
> ... 876543210
> ... 00000
>
> >>> 0b00000
> 60
> >>> 1073741877 & 0b00000
> 52
>
> So this number does _not_ have all zeroes there. If it did, the result
> would be zero. To look for some other pattern, just do the same thing
> - suppose we want to find numbers where it's 1001, we just look for
> the result to be 0b000100100, or 36.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extract Indices of Numpy Array Based on Given Bit Information

2014-10-18 Thread Artur Bercik
Thanks Chris Angelico for your nice answer.
I got some sense, but could not imagine if required Bit No. 2–5, and  Bit
Combination .

I hope example with the new case would make me more sense.

Artur



On Sat, Oct 18, 2014 at 3:24 PM, Chris Angelico  wrote:

> On Sat, Oct 18, 2014 at 4:58 PM, Artur Bercik  wrote:
> > I want to get the index of my data where the following occurs:
> >
> > Bit No. 0–1
> > Bit Combination: 00
>
> So, what you want to do is look at each number in binary, and find the
> ones that have two zeroes in the last two places?
> 1073741824: 100
> 1073741877: 1110101
>
> The easiest way to do this is with simple bitwise operations:
>
> >>> 1073741824 & 3
> 0
> >>> 1073741877 & 3
> 1
>
> 3 is 0011 in binary, so a bitwise AND with that will tell
> you about just the last two bits. The result will be an integer - 0,
> 1, 2, or 3, representing 00, 01, 10, or 11 for those last two bits. So
> all you have to do is AND each number with 3, and when the result is
> 0, that's what you want.
>
> Does that make sense?
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extract Indices of Numpy Array Based on Given Bit Information

2014-10-18 Thread Chris Angelico
On Sat, Oct 18, 2014 at 6:21 PM, Artur Bercik  wrote:
> Thank you very much Chris Angelico, I have come to know it.
>

You're most welcome. And thank you for taking heed of the request to
not top-post. :) Hang around, you never know what weird and wonderful
things you'll learn!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extract Indices of Numpy Array Based on Given Bit Information

2014-10-18 Thread Chris Angelico
On Sat, Oct 18, 2014 at 6:02 PM, Artur Bercik  wrote:
> So, the  Bit No. 2-5 for the following case is '1101', right?
>
> 1073741877: 1110101
>
>  If my required bit combination for Bit No. 2-5 is '1011', then the above
> number (1073741877) is not chosen, right??
>
> Look forward to know your confirmation.

(Side point: Please don't top-post. The convention on this mailing
list, and most other technical mailing lists, is what's sometimes
called "interleaved style"; you trim the quoted text to what's needed
for context, and put your text underneath what you're referring to.
See https://en.wikipedia.org/wiki/Posting_style#Interleaved_style for
more info.)

>>> 1073741877&60
52
>>> bin(52)
'0b110100'

Everything I've written with the triple-angle-bracket marker can be
typed in at the Python prompt, and you'll see exactly what it does. In
this case, you can see that you're absolutely right: 1073741877 has
1101 in those positions, so if you're looking for 1011, it won't
match:

>>> 0b101100
44

However, 1073741869 would:

>>> 1073741869&60
44

The way to test would be something like this:

>>> (1073741877 & 0b00) == 0b101100
False
>>> (1073741869 & 0b00) == 0b101100
True

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


Re: Flush stdin

2014-10-18 Thread Cameron Simpson

On 17Oct2014 12:38, Empty Account  wrote:

I am using netcat to listen to a port and python to read stdin and print to
the console.

nc -l 2003 | python print_metrics.py

sys.stdin.flush() doesn’t seem to flush stdin, so I am using the termios
module. 


You're aware that a stdio flush and a termios flush operate on two totally 
unrelated buffers?



while True: 
   input = sys.stdin.readline()
   # do some parsing 
   …  
   sys.stdout.write(parsed_data)
   time.sleep(3)
   termios.tcflush(sys.stdin, termios.TCIOFLUSH)

I am receiving this exception
termios.error: (25, 'Inappropriate ioctl for device')


That is because stdin is attached to the pipe from netcat. A pipe is not a 
terminal.



I will be using this script on Unix based systems and I wondered what
approach I could use 
to flush stdin?


Like Chris, I think you need to explain why you even want to flush stdin.  
There's probably something better you can do.


Cheers,
Cameron Simpson 

I strongly suspect so.  Practically everyone on sci.physics has a theory that
is far superior to special relativity, general relativity, quantum mechanics
*and* the standard model.  Around here, it's only a small clique of arrogant
young members of the physics establishment who fail to recognize these
revolutionary theories.  I'd explain why, but I have to go finish designing
my faster-than-light vacuum energy perpetual motion telekinetic
aether-powered time machine.- John Baez
--
https://mail.python.org/mailman/listinfo/python-list


Re: [OT] spelling colour / color was Re: Toggle

2014-10-18 Thread giacomo boffi
duncan smith  writes:

> [...] It was the "top / bottom of the [TV] programme" that I didn't
> immediately get, because I was thinking of a timeline running left
> to right (perhaps rather than the script used by the presenters).

is it just me that thinks of a timeline running from the wall behind
the tv set into my dinette?
-- 
https://mail.python.org/mailman/listinfo/python-list