Re: Caching: Access a local file, but ensure it is up-to-date from a remote URL

2014-10-13 Thread Chris Angelico
On Mon, Oct 13, 2014 at 5:36 PM, Ben Finney  wrote:
> So this is something similar to an HTTP object cache. Except where those
> are usually URL-focussed with the local files a hidden implementation
> detail, I want an API that focusses on the local files, with the remote
> requests a hidden implementation detail.

Potential issue: You may need some metadata storage as well as the
actual files. Or can you just ignore the Varies header etc etc etc,
and pretend that this URL represents a single blob of data no matter
what? I'm also dubious about relying on FS timestamps for critical
data, as it's very easy to bump the timestamp to current, which would
make your program think that the contents are fresh; but if that's
truly the only metadata needed, that might be safe to accept.

One way you could possibly do this is to pick up a URL-based cache
(even something stand-alone like Squid), and then create symlinks from
your canonically-named local files to the implementation-detail
storage space for the cache. Then you probe the URL and return its
contents. That guarantees that you're playing nicely with the rules of
HTTP (particularly if you have chained proxies, proxy authentication,
etc, etc - if you're deploying this to arbitrary locations, that might
be an issue), but at the expense of complexity.

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


Re: what is the easiest way to install multiple Python versions?

2014-10-13 Thread Chris Angelico
On Mon, Oct 13, 2014 at 1:31 PM, Rustom Mody  wrote:
> Hearing a bit about docker nowadays.
>
> Here's why its supposedly better than a VM:
> https://www.docker.com/whatisdocker/
>
> Downsides?? No idea!

One obvious downside is that it doesn't allow guests to modify the OS
at all. A VM gives you an entire OS, so you can use and manipulate
anything. If you don't *need* all that flexibility, then a VM is
paying an unnecessary cost, ergo Docker will have no downside.

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


Re: what is the easiest way to install multiple Python versions?

2014-10-13 Thread Rustom Mody
On Monday, October 13, 2014 1:24:27 PM UTC+5:30, Chris Angelico wrote:
> On Mon, Oct 13, 2014 at 1:31 PM, Rustom Mody wrote:
> > Hearing a bit about docker nowadays.
> > Here's why its supposedly better than a VM:
> > https://www.docker.com/whatisdocker/
> > Downsides?? No idea!

> One obvious downside is that it doesn't allow guests to modify the OS
> at all. A VM gives you an entire OS, so you can use and manipulate
> anything. If you don't *need* all that flexibility, then a VM is
> paying an unnecessary cost, ergo Docker will have no downside.

Was talking of more pragmatic downsides eg "Does it really work?" :-)
[Docker is still quite new]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Toggle

2014-10-13 Thread alister
On Mon, 13 Oct 2014 05:43:10 +1100, Chris Angelico wrote:

> On Mon, Oct 13, 2014 at 5:38 AM, Tony the Tiger 
> wrote:
>>> colour = 'red' if colour == 'blue' else 'blue'
>>
>> I call that a subtle bug that most likely will jump up and bite your
>> behind when you least expect it.
> 
> More generally, I'd say that this is solving a (very) slightly different
> problem: it's providing a "toggle with default" feature,
> where the part after the else is the default. If you don't want a
> default, that's a bug. I've known times when that default makes life a
> lot easier, in which case it'd be a feature.
> 
> ChrisA

if the value of colour is being set by user input & an incorrect value 
can be set the the error is in not validating user input and more complex 
solutions are definitely req.

If the value is being set within the program itself and colour gets set 
to an incorrect value the bug lies elsewhere in the program.

this looks like a simple requirement to alternate the colour of a GUI 
element so it is unlikely that incorrect values will be set.

sometimes it is easy to get carried away & overcomplicate a simple task, 
I tend to follow the "KISS" principle wherever possible 



-- 
40 isn't old.  If you're a tree.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: while loop - multiple condition

2014-10-13 Thread Gelonida N

On 10/12/2014 07:08 PM, Shiva wrote:

while ans.lower() != 'yes' or ans.lower()[0] != 'y':
  ans = input('Do you like python?')


I personally consider double negations less intuitive than following:


while not( ans.lower() == 'yes' and ans.lower()[0] == 'y' ):

Reading this line yoy would have noticed as wellm that what you really 
wanted would have been:


while not( ans.lower() == 'yes' or ans.lower()[0] == 'y' ):



I would write the coder differently.

With your code you have to pre-initialze the variable ans.


I personally consider it also more 'intuitive' / easier to understand if
I can see the break conditiion. to many nots  / != / negations can be 
confusing as you noticed yourself.


Taking into account the Steven's suggestion about using the 'in' 
expression it could be:



while True:
ans = input('Do you like python?')
if ans.lower() in ('yes', 'y'):
break






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


windows 7 pysqlite build error

2014-10-13 Thread Robin Becker
I am getting this error trying to use a python27 pip install of stuff which ends 
up requiring pysqlite>=2.6.3,<2.7



building 'pysqlite2._sqlite' extension

creating build\temp.win-amd64-2.7

creating build\temp.win-amd64-2.7\Release

creating build\temp.win-amd64-2.7\Release\src

c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\amd64\cl.exe /c 
/nologo /Ox /MD /W3 /GS- /DNDEBUG -DMODULE_NAM
E=\"pysqlite2.dbapi2\" -DSQLITE_OMIT_LOAD_EXTENSION=1 -IC:\python27\include 
-IC:\Users\rptlab\tmp\tenv\PC /Tcsrc/
module.c /Fobuild\temp.win-amd64-2.7\Release\src/module.obj
module.c

c:\users\rptlab\tmp\tmcallister\build\pysqlite\src\connection.h(33) : fatal 
error C1083: Cannot open include file: 'sqli
te3.h': No such file or directory

error: command 'c:\\Program Files (x86)\\Microsoft Visual Studio 
9.0\\VC\\BIN\\amd64\\cl.exe' failed with exit status 2


Cleaning up...



I do have the various compilers installed and other extensions are building OK, 
so is this an error in pysqlite or in my general setup? The include path looks 
like it might relate to Python builds. I suppose it's feasible that pyqslite 
builds need to be installed specially. I don't remember this happening on my old 
win32 XP system, but that died and I now am forced to use 64bit win7.

--
Robin Becker


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


Re: TypeError: 'kwarg' is an invalid keyword argument for this function

2014-10-13 Thread Dave Angel
Ian Kelly  Wrote in message:
> On Sun, Oct 12, 2014 at 6:55 AM, roro codeath  wrote:
>> How to implement it in my class?
>>
>> class Str(str):
>> def __init__(self, *args, **kwargs):
>> pass
>>
>> Str('smth', kwarg='a')
> 
> The error is coming from the __new__ method. Because str is an
> immutable type, you should override the __new__ method, not __init__.
> Example:
> 
> class Str(str):
> def __new__(cls, *args, **kwargs):
> return super().__new__(cls, args[0])
> 
 Str('smth', kwarg='a')
> 'smth'
> 

It would also help to spell it the same.  In the OP's
 implementation,  he defined kwargs, and tried to use it as
 kwarg.


-- 
DaveA

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


Re: TypeError: 'kwarg' is an invalid keyword argument for this function

2014-10-13 Thread Peter Otten
Dave Angel wrote:

> Ian Kelly  Wrote in
> message:
>> On Sun, Oct 12, 2014 at 6:55 AM, roro codeath
>>  wrote:
>>> How to implement it in my class?
>>>
>>> class Str(str):
>>> def __init__(self, *args, **kwargs):
>>> pass
>>>
>>> Str('smth', kwarg='a')
>> 
>> The error is coming from the __new__ method. Because str is an
>> immutable type, you should override the __new__ method, not __init__.
>> Example:
>> 
>> class Str(str):
>> def __new__(cls, *args, **kwargs):
>> return super().__new__(cls, args[0])
>> 
> Str('smth', kwarg='a')
>> 'smth'
>> 
> 
> It would also help to spell it the same.  In the OP's
>  implementation,  he defined kwargs, and tried to use it as
>  kwarg.

That is consistent as should become clear when using something completely 
different:

>>> class Str(str):
... def __init__(self, *args, **kwargs): pass
... 
>>> Str("smth", alpha="beta")
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'alpha' is an invalid keyword argument for this function


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


Jython or Pyton issue-- Kindly Help me....

2014-10-13 Thread Venugopal Reddy
Dear All,

How to write a program for reading or parsing the XML file in Sub root Wise.

For ex:

Below XMl, I want to read/ parse first country details and here also two year 
tag values are there.. Here I need to read/parse first year value only measn 
'2008' Only..After that I need to read second country details.

Please help me .. i am struggling to get this solution..




1
2008
2009>
141100




4
2011
59900



68
2011
13600



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


Re: while loop - multiple condition

2014-10-13 Thread Chris Angelico
On Mon, Oct 13, 2014 at 7:31 PM, Gelonida N  wrote:
> Taking into account the Steven's suggestion about using the 'in' expression
> it could be:
>
>
> while True:
> ans = input('Do you like python?')
> if ans.lower() in ('yes', 'y'):
> break

Or, even simpler: Use an active condition.

while input('Do you like python?') not in ('yes', 'y'): pass

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


Re: while loop - multiple condition

2014-10-13 Thread Marko Rauhamaa
Chris Angelico :

> Or, even simpler: Use an active condition.
>
> while input('Do you like python?') not in ('yes', 'y'): pass

Instead of the traditional "pull" technology, you could take advantage
of the state-of-the-art "push" approach:

   print("You must love python -- everybody does!")


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


Re: while loop - multiple condition

2014-10-13 Thread Skip Montanaro
On Mon, Oct 13, 2014 at 6:59 AM, Chris Angelico  wrote:

> while input('Do you like python?') not in ('yes', 'y'): pass


Unfortunately, you probably have to account for people who SHOUT:

while input('Do you like python?').lower() not in ('yes', 'y'): pass



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


Re: while loop - multiple condition

2014-10-13 Thread Chris Angelico
On Mon, Oct 13, 2014 at 11:10 PM, Skip Montanaro
 wrote:
> On Mon, Oct 13, 2014 at 6:59 AM, Chris Angelico  wrote:
>>
>> while input('Do you like python?') not in ('yes', 'y'): pass
>
>
> Unfortunately, you probably have to account for people who SHOUT:
>
> while input('Do you like python?').lower() not in ('yes', 'y'): pass
>
> 

Welcome to collaborative editing. I make a change and introduce a bug.
Fortunately, someone else can, just like that, fix that bug. Thanks!
:)

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


Re: while loop - multiple condition

2014-10-13 Thread Chris Angelico
On Mon, Oct 13, 2014 at 11:09 PM, Marko Rauhamaa  wrote:
> Chris Angelico :
>
>> Or, even simpler: Use an active condition.
>>
>> while input('Do you like python?') not in ('yes', 'y'): pass
>
> Instead of the traditional "pull" technology, you could take advantage
> of the state-of-the-art "push" approach:
>
>print("You must love python -- everybody does!")

Nay, there is love in excess. I thank heaven there are many pythons in
England; but if thou lovest them all, I withdraw my thanks!
-- Colonel Fairfax

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


Re: what is the easiest way to install multiple Python versions?

2014-10-13 Thread Chris Angelico
On Mon, Oct 13, 2014 at 7:00 PM, Rustom Mody  wrote:
> On Monday, October 13, 2014 1:24:27 PM UTC+5:30, Chris Angelico wrote:
>> On Mon, Oct 13, 2014 at 1:31 PM, Rustom Mody wrote:
>> > Hearing a bit about docker nowadays.
>> > Here's why its supposedly better than a VM:
>> > https://www.docker.com/whatisdocker/
>> > Downsides?? No idea!
>
>> One obvious downside is that it doesn't allow guests to modify the OS
>> at all. A VM gives you an entire OS, so you can use and manipulate
>> anything. If you don't *need* all that flexibility, then a VM is
>> paying an unnecessary cost, ergo Docker will have no downside.
>
> Was talking of more pragmatic downsides eg "Does it really work?" :-)
> [Docker is still quite new]

Ah, I can't help you there. I've never used Docker.

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


Re: what is the easiest way to install multiple Python versions?

2014-10-13 Thread Ned Batchelder

On 10/12/14 9:33 AM, Albert-Jan Roskam wrote:

Hi,

(sorry for cross-posting)

A few days ago I needed to check whether some Python code ran with Python 2.6. 
What is the easiest way to install another Python version along side the 
default Python version? My own computer is Debian Linux 64 bit, but a 
platform-independent solution would be best.

Possible solutions that I am aware of

-make altinstall *). This is what I tried (see below), but not all modules 
could be built. I gave up because I was in a hurry
-Pythonbrew. This project is dead
-Deadsnakes
-Anaconda
-Tox? I only know this is as a cross-version/implementation test runner
-Vagrant. This is what I eventually did, and this was very simple. I ran Ubuntu 
10.0.4 LTS, which uses Python 2.6, and used Vagrant SSH to run and check my 
code in Python 2.6 (and I replaced a dict comprehension with a list 
comprehension, for example)
- ...

What is the recommended way? I don't expect/hope that I'd ever need something 
lower than Python 2.5


I use pythonz: http://saghul.github.io/pythonz/  It lets me specify not 
just the version I want, but the implementation I want: I can install 
CPython 2.6.1, PyPy 2.0.2, and Jython 2.5.3 all the same way.


--
Ned Batchelder, http://nedbatchelder.com

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


Re: Jython or Pyton issue-- Kindly Help me....

2014-10-13 Thread Ian Kelly
On Mon, Oct 13, 2014 at 5:39 AM, Venugopal Reddy
 wrote:
> Dear All,
>
> How to write a program for reading or parsing the XML file in Sub root Wise.

I don't know what "Sub root Wise" is. You can find an overview of
Python's XML parsing interfaces at
https://docs.python.org/2/library/xml.html. I would recommend using
the ElementTree API unless you have a specific reason to use something
else.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: while loop - multiple condition

2014-10-13 Thread Rob Gaddi
On Mon, 13 Oct 2014 09:56:02 +1100
Steven D'Aprano  wrote:
> 
> When you have multiple clauses in the condition, it's easier to reason about
> them if you write the clauses as positive statements rather than negative
> statements, that is, "something is true" rather than "something is not
> true", and then use `not` to reverse it if you want to loop *until* the
> overall condition is true.
> 

I was just explaining this concept to a young pup the other day.  De
Morgan's lets you say that (not (p and q)) == ((not p) or (not q)), but
the positive logic flavor is substantially less error-prone.  People
are fundamentally not as good at thinking about inverted logic.

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: while loop - multiple condition

2014-10-13 Thread Rustom Mody
On Monday, October 13, 2014 9:43:03 PM UTC+5:30, Rob Gaddi wrote:
> On Mon, 13 Oct 2014 09:56:02 +1100
> Steven D'Aprano  wrote:
> > When you have multiple clauses in the condition, it's easier to reason about
> > them if you write the clauses as positive statements rather than negative
> > statements, that is, "something is true" rather than "something is not
> > true", and then use `not` to reverse it if you want to loop *until* the
> > overall condition is true.

> I was just explaining this concept to a young pup the other day.  De
> Morgan's lets you say that (not (p and q)) == ((not p) or (not q)), but
> the positive logic flavor is substantially less error-prone.  People
> are fundamentally not as good at thinking about inverted logic.

Curious: Which of

- (not (p and q))
- ((not p) or (not q))

is more positive (less negative)??
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: while loop - multiple condition

2014-10-13 Thread Rob Gaddi
On Mon, 13 Oct 2014 09:26:57 -0700 (PDT)
Rustom Mody  wrote:

> On Monday, October 13, 2014 9:43:03 PM UTC+5:30, Rob Gaddi wrote:
> > On Mon, 13 Oct 2014 09:56:02 +1100
> > Steven D'Aprano  wrote:
> > > When you have multiple clauses in the condition, it's easier to reason 
> > > about
> > > them if you write the clauses as positive statements rather than negative
> > > statements, that is, "something is true" rather than "something is not
> > > true", and then use `not` to reverse it if you want to loop *until* the
> > > overall condition is true.
> 
> > I was just explaining this concept to a young pup the other day.  De
> > Morgan's lets you say that (not (p and q)) == ((not p) or (not q)), but
> > the positive logic flavor is substantially less error-prone.  People
> > are fundamentally not as good at thinking about inverted logic.
> 
> Curious: Which of
> 
> - (not (p and q))
> - ((not p) or (not q))
> 
> is more positive (less negative)??

The first is asking you to compare positive conditions (p and q) and
negate the entire thing (NAND).  The second asks you to think about
the combination of two different "not true" pieces of logic
(OR of two inverted inputs).  The first is pretty straightforward, and
I usually see people get it right.  The second gets screwed up as often
as not.

And of course, any combination of ands and ors should be broken into
multiple statements with a descriptive variable name in the middle or
all hope is lost.

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: while loop - multiple condition

2014-10-13 Thread Rustom Mody
On Monday, October 13, 2014 10:13:20 PM UTC+5:30, Rob Gaddi wrote:
> On Mon, 13 Oct 2014 09:26:57 -0700 (PDT)
> Rustom Mody  wrote:

> > On Monday, October 13, 2014 9:43:03 PM UTC+5:30, Rob Gaddi wrote:
> > > On Mon, 13 Oct 2014 09:56:02 +1100
> > > Steven D'Aprano  wrote:
> > > > When you have multiple clauses in the condition, it's easier to reason 
> > > > about
> > > > them if you write the clauses as positive statements rather than 
> > > > negative
> > > > statements, that is, "something is true" rather than "something is not
> > > > true", and then use `not` to reverse it if you want to loop *until* the
> > > > overall condition is true.
> > > I was just explaining this concept to a young pup the other day.  De
> > > Morgan's lets you say that (not (p and q)) == ((not p) or (not q)), but
> > > the positive logic flavor is substantially less error-prone.  People
> > > are fundamentally not as good at thinking about inverted logic.
> > Curious: Which of
> > - (not (p and q))
> > - ((not p) or (not q))
> > is more positive (less negative)??

> The first is asking you to compare positive conditions (p and q) and
> negate the entire thing (NAND).  The second asks you to think about
> the combination of two different "not true" pieces of logic
> (OR of two inverted inputs).  The first is pretty straightforward, and
> I usually see people get it right.  The second gets screwed up as often
> as not.

> And of course, any combination of ands and ors should be broken into
> multiple statements with a descriptive variable name in the middle or
> all hope is lost.

Yeah I guess 2 nots is one more than one!

However (to my eyes)
while i < N  and  a[i] != X:

looks less negative than

while not (i==N or a[i] == X):

[Of course i < N is not identical to i != N ]
-- 
https://mail.python.org/mailman/listinfo/python-list


How to select every other line from a text file?

2014-10-13 Thread Rff
Hi,
I have a text file. Now it is required to select every other line of that text 
to
 generate a new text file. I have read through Python grammar, but still lack 
the
 idea at the beginning of the task. Could you tell me some methods to get this?


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


Re: How to select every other line from a text file?

2014-10-13 Thread Chris Angelico
On Tue, Oct 14, 2014 at 4:38 AM, Rff  wrote:
> I have a text file. Now it is required to select every other line of that 
> text to
>  generate a new text file. I have read through Python grammar, but still lack 
> the
>  idea at the beginning of the task. Could you tell me some methods to get 
> this?
>

There are a few ways of doing this. I'm guessing this is probably a
homework assignment, so I won't give you the code as-is, but here are
a few ideas:

1) Iterate over the file (line by line), alternating between writing
the line out and not writing the line out.
2) Read the file into a list of lines, then slice the list with a step
of 2, and write those lines out.
3) Iterate over the file, but also consume an extra line at the top or
bottom of the loop.
4) Read the entire file into a string, then abuse regular expressions
violently until they do what you want.

And there are other ways, too. Show us some code and we can help you
with it; but at the moment, this is fairly open-ended.

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


Re: How to select every other line from a text file?

2014-10-13 Thread John Gordon
In <3be64ca8-d2e7-493a-b4f3-ef114f581...@googlegroups.com> Rff 
 writes:

> Hi,
> I have a text file. Now it is required to select every other line of that
> text to generate a new text file. I have read through Python grammar, but
> still lack the idea at the beginning of the task. Could you tell me some
> methods to get this?

Initialize a counter variable to zero.  (Or one, depending if you want to
select odd or even lines.)

Each time you read a line from the file, add one to the counter.

If the counter is odd, process the line; otherwise use the 'continue'
statement to start the loop over and read another line.

-- 
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: How to select every other line from a text file?

2014-10-13 Thread Gary Herron

On 10/13/2014 10:38 AM, Rff wrote:

Hi,
I have a text file. Now it is required to select every other line of that text 
to
  generate a new text file. I have read through Python grammar, but still lack 
the
  idea at the beginning of the task. Could you tell me some methods to get this?


Thanks,


Read in your lines, keeping a counter as you go.  "Select" those lines 
whose counter is even (or odd -- you didn't say which you wanted).


So now some questions for you:

 * Do you know how to open a file and read in all the lines?
 * Do you know how to count as you do so?
 * Do you know how to test for evenness?   (Use count%2 will be zero
   for even count values.)
 * Do you know how to write lines to an output file?

Gary Herron

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


Re: How to select every other line from a text file?

2014-10-13 Thread Mark Lawrence

On 13/10/2014 18:48, John Gordon wrote:

In <3be64ca8-d2e7-493a-b4f3-ef114f581...@googlegroups.com> Rff 
 writes:


Hi,
I have a text file. Now it is required to select every other line of that
text to generate a new text file. I have read through Python grammar, but
still lack the idea at the beginning of the task. Could you tell me some
methods to get this?


Initialize a counter variable to zero.  (Or one, depending if you want to
select odd or even lines.)

Each time you read a line from the file, add one to the counter.

If the counter is odd, process the line; otherwise use the 'continue'
statement to start the loop over and read another line.



Why bother to initialise a counter when you can get the enumerate 
function to do all the work for 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: How to select every other line from a text file?

2014-10-13 Thread emile

On 10/13/2014 11:02 AM, Mark Lawrence wrote:


Why bother to initialise a counter when you can get the enumerate
function to do all the work for you?


I see it as a question of addressing the audience.

Emile



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


scipy errors and gfortran

2014-10-13 Thread slyost
Trying to get scipy 0.14 running on python 3.4.1 on SLES 11 SP2 LINUX system.
Scipy seemed to compile fine using the command "python setup.py install" but 
when I try the scipy.test("full"), I get errors regarding gfortran.  I am using 
GCC(gfortran) version 4.9.1.

The error states that /usr/lib/libgfortran.so.3: version 'gfortran_1.4' was not 
found (required by).  Google tells me that this is the name of the symbol 
node whatever that means.

What do I need to do to fix these errors?  Please help.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to select every other line from a text file?

2014-10-13 Thread Joel Goldstick
On Mon, Oct 13, 2014 at 2:11 PM, emile  wrote:
> On 10/13/2014 11:02 AM, Mark Lawrence wrote:
>
>> Why bother to initialise a counter when you can get the enumerate
>> function to do all the work for you?
>
>
> I see it as a question of addressing the audience.
>
> Emile

I don't agree with the idea of using a counter.  Its not pythonic, and
I'm assuming the OP is just starting to learn python.

Not apropos to the OP, but what came up in my mind was to write a
generator function that returns every other line.  This would separate
the reading from the writing code.

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



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


Re: How to select every other line from a text file?

2014-10-13 Thread Grant Edwards
On 2014-10-13, Chris Angelico  wrote:
> On Tue, Oct 14, 2014 at 4:38 AM, Rff  wrote:
>> I have a text file. Now it is required to select every other line of that 
>> text to
>>  generate a new text file. I have read through Python grammar, but still 
>> lack the
>>  idea at the beginning of the task. Could you tell me some methods to get 
>> this?
>>
>
> There are a few ways of doing this. I'm guessing this is probably a
> homework assignment, so I won't give you the code as-is, but here are
> a few ideas:
>
> 1) Iterate over the file (line by line), alternating between writing
>the line out and not writing the line out.
>
> 2) Read the file into a list of lines, then slice the list with a step
>of 2, and write those lines out.
>
> 3) Iterate over the file, but also consume an extra line at the top or
>bottom of the loop.
>
> 4) Read the entire file into a string, then abuse regular expressions
>violently until they do what you want.

I'd vote for #3.  Or write a generator that does something similar
when given a parameter object that implements readline().

Of course, the _real_ answer is:

os.system("sed -n 'g;n;p' '%s'" % filename)

;)

-- 
Grant Edwards   grant.b.edwardsYow! Didn't I buy a 1951
  at   Packard from you last March
  gmail.comin Cairo?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to select every other line from a text file?

2014-10-13 Thread Tim Chase
On 2014-10-13 10:38, Rff wrote:
> Hi,
> I have a text file. Now it is required to select every other line
> of that text to generate a new text file. I have read through
> Python grammar, but still lack the idea at the beginning of the
> task. Could you tell me some methods to get this?

You could force a re-read from the file each line:

  with open("x.txt") as f:
for line in f:
  do_something(line)
  next(f)  # discard/consume the next line

Or, if you have it read into memory already, you could use slicing
with a stride of 2:

  with open("x.txt") as f:
data = f.readlines()
interesting = data[::2] # start with the 1st line
# interesting = data[1::2] # start with the 2nd line

Or, if the file was large and you didn't want to have it all in
memory at the same time, you could use itertools.islice()

  from itertools import islice
  with open("x.txt") as f:
interesting = islice(f, 0, None, 2) # start with 1st line
#interesting = islice(f, 1, None, 2) # start with 2nd line

Note that in the last one, you get an iterator back, so you'd have to
either turn it into a list or iterate over it.

-tkc



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


Re: How to select every other line from a text file?

2014-10-13 Thread Tim Chase
On 2014-10-13 14:45, Joel Goldstick wrote:
> Not apropos to the OP, but what came up in my mind was to write a
> generator function that returns every other line.  This would
> separate the reading from the writing code.

You mean like

  offset = 0 # or 1 if you prefer
  for line in itertools.islice(source_iter, offset, None, 2):
do_something(line)

?

-tkc


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


Re: How to select every other line from a text file?

2014-10-13 Thread emile

On 10/13/2014 12:12 PM, Tim Chase wrote:


You mean like

   offset = 0 # or 1 if you prefer
   for line in itertools.islice(source_iter, offset, None, 2):
 do_something(line)



I certainly did.  Learning the python standard library is different from 
learning python and each in its own time.


Emile




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


Re: windows 7 pysqlite build error

2014-10-13 Thread Terry Reedy

On 10/13/2014 4:31 PM, Dennis Lee Bieber wrote:

On Mon, 13 Oct 2014 10:49:27 +0100, Robin Becker 
declaimed the following:


c:\users\rptlab\tmp\tmcallister\build\pysqlite\src\connection.h(33) : fatal 
error C1083: Cannot open include file: 'sqli
te3.h': No such file or directory


Did \n get stuck in the name of the file in connection.h, or is that 
purely an artifact of the error reporting?



error: command 'c:\\Program Files (x86)\\Microsoft Visual Studio 
9.0\\VC\\BIN\\amd64\\cl.exe' failed with exit status 2



I do have the various compilers installed and other extensions are building OK,
so is this an error in pysqlite or in my general setup? The include path looks
like it might relate to Python builds. I suppose it's feasible that pyqslite
builds need to be installed specially. I don't remember this happening on my old
win32 XP system, but that died and I now am forced to use 64bit win7.


Off hand, you don't have the SQLite3 /development package/.

PySQLite is just an adapter to the sqlite3 DLL; the sqlite3.h file
would be part of the source code for sqlite3, not part of pysqlite itself.




--
Terry Jan Reedy

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


Re: Flask and Django

2014-10-13 Thread Michael Torrie
On 10/10/2014 04:22 PM, Juan Christian wrote:
> Maybe that's because I feel the Django doc a bit confuse, I tried reading
> (and practicing!) tutorials, official doc, books, and so on, but I can't
> quite understand the whole thing.
> 
> Is Flask really underestimated? Can you guys mention "big name" companies
> or people using it? Does it have real value in real world business?

Nothing wrong with using Flask, especially for a personal project, or
even something commercial.

That said, Django is pretty easy to get started with.  I have done very
little web development ever, and I can fairly easily get going with
Django.  The tutorials are quite good.  If you have problems with them,
you can get help on the django mailing lists and forums, I am sure.
Django does seem to get a lot of attention.  It's getting to be a huge
framework, with lots of bells and whistles, but I'm pretty sure you can
still use as much or as little of it as you need, and even discard parts
of it, such as the native Django database persistance API, and use, say,
sqalchemy.

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


Re: while loop - multiple condition

2014-10-13 Thread Michael Torrie
On 10/13/2014 11:12 AM, Rustom Mody wrote:
> On Monday, October 13, 2014 10:13:20 PM UTC+5:30, Rob Gaddi wrote:
>> On Mon, 13 Oct 2014 09:26:57 -0700 (PDT)
>> Rustom Mody  wrote:
> 
>>> On Monday, October 13, 2014 9:43:03 PM UTC+5:30, Rob Gaddi wrote:
 On Mon, 13 Oct 2014 09:56:02 +1100
 Steven D'Aprano  wrote:
> When you have multiple clauses in the condition, it's easier to reason 
> about
> them if you write the clauses as positive statements rather than negative
> statements, that is, "something is true" rather than "something is not
> true", and then use `not` to reverse it if you want to loop *until* the
> overall condition is true.
 I was just explaining this concept to a young pup the other day.  De
 Morgan's lets you say that (not (p and q)) == ((not p) or (not q)), but
 the positive logic flavor is substantially less error-prone.  People
 are fundamentally not as good at thinking about inverted logic.
>>> Curious: Which of
>>> - (not (p and q))
>>> - ((not p) or (not q))
>>> is more positive (less negative)??
> 
>> The first is asking you to compare positive conditions (p and q) and
>> negate the entire thing (NAND).  The second asks you to think about
>> the combination of two different "not true" pieces of logic
>> (OR of two inverted inputs).  The first is pretty straightforward, and
>> I usually see people get it right.  The second gets screwed up as often
>> as not.
> 
>> And of course, any combination of ands and ors should be broken into
>> multiple statements with a descriptive variable name in the middle or
>> all hope is lost.
> 
> Yeah I guess 2 nots is one more than one!
> 
> However (to my eyes)
> while i < N  and  a[i] != X:
> 
> looks less negative than
> 
> while not (i==N or a[i] == X):
> 
> [Of course i < N is not identical to i != N ]

Right it should have been not (i >= N or a[i] == X) to be equivalent.

In assembler it's often best to reverse the condition and then use the
opposite jump mnemonic. IE, if the test is to see if a number not zero,
use the jump if zero command instead.  Often it reduces the number of
jumps required and eliminates the need to jump over the body of the "if"
block.

if a != 0 then jump to bigger
jump to end
bigger:
blah
blah
end:

vs

if a == 0 then jump to end
blah
blah
end:



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


Re: How to select every other line from a text file?

2014-10-13 Thread Denis McMahon
On Mon, 13 Oct 2014 10:38:48 -0700, Rff wrote:

> I have a text file. Now it is required to select every other line of
> that text to
>  generate a new text file. I have read through Python grammar, but still
>  lack the idea at the beginning of the task. Could you tell me some
>  methods to get this?

So this could be written as an algorithm something like:

1/ open the input file
2/ open the output file
3/ while there are lines to read from the input file
3/1/ read a line from the input file
3/2/ if I should output this line
3/2/1/ write line to output file
4/ close the input file
5/ close the output file

Or in several other ways, and once you have an algorithm, you can start 
coding it (or implementing it in the programming language of your choice, 
whichever form of words best pleases your perfesser).

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


Re: How to select every other line from a text file?

2014-10-13 Thread Dan Stromberg
On Mon, Oct 13, 2014 at 10:38 AM, Rff  wrote:
> Hi,
> I have a text file. Now it is required to select every other line of that 
> text to
>  generate a new text file. I have read through Python grammar, but still lack 
> the
>  idea at the beginning of the task. Could you tell me some methods to get 
> this?

Perhaps something like:
http://stromberg.dnsalias.org/svn/every-nth/trunk

It uses zip and itertools.cycle.

It's CPython 3.x though - if you need 2.x, you'd probably use xrange
instead of range, and izip instead of zip.
-- 
https://mail.python.org/mailman/listinfo/python-list


Need help in pulling SQL query out of log file...

2014-10-13 Thread Sagar Deshmukh
Hi,

I have a log file which has lot of information like..SQL query.. number of 
records read...records loaded etc..

My requirement is i would like to read the SQL query completly and write it to 
another txt file.. also the log file may not be always same so can not make 
static choices...

my logfile is like below :

*LOg file starts**


Fri Aug 08 16:00:04 2014 : WRITER_1_*_1> WRT_8005 Writer run started.
Fri Aug 08 16:00:04 2014 : READER_1_2_1> BLKR_16007 Reader run started.
Fri Aug 08 16:00:04 2014 : WRITER_1_*_1> WRT_8158 

*START LOAD SESSION*

Load Start Time: Fri Aug 08 16:00:04 2014

Target tables:

 EIS_REQUEST_LOG_26MAYBKP
 T_delta_parm_file


Fri Aug 08 16:00:04 2014 : READER_1_2_1> RR_4010 SQ instance 
[SQ_Shortcut_to_EIS_REQUEST_LOG] SQL Query [SELECT 
EIS_REQUEST_LOG_26MAYBKP.RqstId, EIS_REQUEST_LOG_26MAYBKP.RQSTLoadStatCd FROM 
EIS_REQUEST_LOG_26MAYBKP]
Fri Aug 08 16:00:04 2014 : READER_1_2_1> RR_4049 RR_4049 SQL Query issued to 
database : (Fri Aug 08 16:00:04 2014)
Fri Aug 08 16:00:04 2014 : READER_1_2_1> RR_4035 SQL Error [
FnName: Prepare -- [Teradata][ODBC Teradata Driver][Teradata Database] Object 
'EIS_REQUEST_LOG_26MAYBKP' does not exist. ].
Fri Aug 08 16:00:04 2014 : READER_1_2_1> BLKR_16004 ERROR: Prepare failed.
Fri Aug 08 16:00:04 2014 : READER_1_1_1> RR_4029 SQ Instance [SQ_RSTS_Tables] 
User specified SQL Query [--- Approved By ICC Team---
---SELECT A.LOGSYS , 
---D."/BIC/NIGNRCSYS" ,
---B.ODSNAME ,
---C.ODSNAME_TECH , 
---C.PARTNO , 
---C.REQUEST ,
---E.SID 
---FROM
---sapbzd."RSISOSMAP"  A, 
---sapbzd."RSTSODS"  B, 
---sapbzd."RSTSODSPART"   C,
---sapbzd."/BIC/PNIGNRCSYS"   D,
---sapbzd."/BI0/SREQUID"   E,
---sapbzd."RSMONMESS"F
---WHERE A.OLTPSOURCE = 
('ZNK_SHP_DDLN_CREATE_BE','ZNK_KNVP2_BD','ZNK_ZVBW_RTN_ORD_ITM_BN','2LIS_02_SCL_BE','ZNK_FX_CRCY_HIS_BE','ZNK_PO_FX_CALC_LOG_BD','2LIS_12_VCHDR_BE','2LIS_02_HDR_BN','ZNK_SHP_DDLN_CHANGE_BD','1_CO_PAGL11000N1_BE','0CUSTOMER_ATTR_BE','2LIS_08TRTLP_BD','2LIS_02_SCN_BD','2LIS_02_HDR_BD','2LIS_13_VDITM_BE','0CO_OM_CCA_9_BE','ZNK_SO_BDSI_OPNDMD_BE','2LIS_11_VAHDR_BE','ZNK_ZVBW_MBEW_BE','2LIS_13_VDHDR_BN','ZNK_SHP_DDLN_CHANGE_BE','NK_ADDR_NUMBR_BN','0CUSTOMER_TEXT_BE','6DB_J_3ABD_DELTA_AFFL_AD','0MAT_PLANT_ATTR_BE','ZNK_BDCPV_BD','1_CO_PAGL11000N1_BD','2LIS_11_VASTI_BD','ZNK_ZVBW_MSKU_BE','ZNK_SHP_DDLN_CREATE_BD','0SCEM_1_BC','2LIS_11_VAHDR_BD','2LIS_11_VASCL_BD','0MATERIAL_TEXT_BE','0MATERIAL_ATTR_BE','ZNK_BDCPV_BE','2LIS_02_ITM_BN','2LIS_11_VASCL_BE','2LIS_11_VAITM_BN','NK_ADDR_NUMBR_BE','2LIS_08TRTK_BE','ZNK_SD_LIKPPS_BN','2LIS_03_BF_BE','ZNK_SO_BDBS_ALLOC_BD','ZNK_TD_3AVASSO_BN','0EC_PCA_3_BD','ZNK_TD_3AVAP_BE','2LIS_11_VAITM_BE','0CUST_SALES_ATTR_BN','0EC_PCA_3_
 
BE','2LIS_13_VDITM_BN','2LIS_11_VASTH_BD','2LIS_13_VDITM_BD','0CUST_SALES_ATTR_BD','ZNK_TD_3AVASSO_BD','2LIS_02_SCN_BE','2LIS_08TRTS_BD','0CUSTOMER_ATTR_BN','ZNK_TD_3AVASSO_BE','ZNK_ZVBW_MSLB_BE','ZNK_TD_3AVAP_BD','0CUSTOMER_TEXT_BN','6DB_J_3ABD_DELTA_US_AD','0CUSTOMER_TEXT_BD','2LIS_11_VAHDR_BN','ZNK_SO_BDBS_ALLOC_BN','0GL_ACCOUNT_TEXT_BE','0GL_ACCOUNT_TEXT_BD','2LIS_11_VAITM_BD','ZNK_TD_3AVATL_BE','ZNK_SO_BDBS_ALLOC_BE','ZNK_EBAN_BE','ZNK_SO_BDSI_OPNDMD_BN','ZNK_SD_LIKPPS_BD','ZNK_ZVBW_RTN_ORD_ITM_BE','2LIS_08TRTS_BN','2LIS_02_HDR_BE','ZNK_TD_3AVATL_BD','ZNK_VBPA_BE','ZNK_FX_CRCY_HIS_BD','2LIS_13_VDHDR_BE','NK_ADDR_NUMBR_BD','2LIS_12_VCITM_BD','2LIS_08TRTK_BD','2LIS_11_VASCL_BN','ZNK_ZVBW_MCHB_BE','6DB_J_3ABD_SCL_DELTA_AP_AE','ZNK_SO_BDSI_OPNDMD_BD','ZNK_KNVP2_BE','0MAT_SALES_ATTR_BE','ZNK_TD_3AVAP_BN','2LIS_13_VDHDR_BD','0GL_ACCOUNT_ATTR_BD','2LIS_02_SCL_BD','ZNK_VBPA_BD','2LIS_02_ITM_BD','ZNK_TD_3AVATL_BN','ZNK_ZVBW_RTN_ORD_ITM_BD','ZNK_PO_FX_CALC_LOG_BE','6DB_J_3ABD_DELTA_EMEA_
 AD','0GL_ACCOUNT_ATTR_BE','2LIS_03_BF_BD','2!
 LIS_11_V
ASTI_BE','0CO_OM_CCA_9_BD','0CUST_SALES_ATTR_BE','2LIS_12_VCITM_BE','0CUSTOMER_ATTR_BD','2LIS_02_ITM_BE','2LIS_08TRTLP_BE','2LIS_12_VCHDR_BD','ZNK_EBAN_BD','2LIS_08TRTS_BE','2LIS_02_SCL_BN','2LIS_11_VASTH_BE','ZNK_SD_LIKPPS_BE')
---AND A.LOGSYS = D."/BIC/NKLOGSYST"
---AND A.OBJVERS = 'A'
---AND A.TRANSTRU =  B.ODSNAME 
---AND B.DATETO = 0101
---AND B.OBJSTAT = 'ACT'
---AND B.ODSNAME_TECH = C.ODSNAME_TECH
---AND C.DELFLAG <> 'X'
---AND D."/BIC/NIGNRCSYS" = ('R3_PRA','R3_PRD','R3_PRF','EM_EMP')
---AND D.OBJVERS = 'A'
---AND E.REQUID = C.REQUEST
---AND F.RNR = C.REQUEST
---AND F.MSGNO = '344'
---AND F.AUFRUFER = '09'---

SELECT A.LOGSYS , 
D."/BIC/NIGNRCSYS" ,
B.ODSNAME ,
C.ODSNAME_TECH , 
C.PARTNO , 
C.REQUEST ,
E.SID 
FROM
sapbzd."RSISOSMAP"  A, 
sapbzd."RSTSODS"  B, 
sapbzd."RSTSODSPART"   C,
sapbzd."/BIC/PNIGNRCSYS"   D,
sapbzd."/BI0/SREQUID"   E,
sapbzd."RSMONMESS"F
WHERE 
A.OLTPSOURCE in 
('ZNK_SHP_DDLN_CREATE_BE','ZNK_KNVP2_BD','ZNK_ZVBW_RTN_ORD_ITM_BN','2LIS_02_SCL_BE','ZNK_FX_CRCY_HIS_BE','ZNK_PO_FX_CALC_LOG_BD','2LIS_12_VCHDR_BE','2LIS_02_HDR_BN','ZNK_SHP_DDLN_CHANGE_BD','1_CO_PAGL11000N1_BE','0CUSTOMER_ATTR_BE','2LIS_08TRTLP_BD','2LIS_02_SCN_BD','2LIS_02_HDR_BD','2LIS_13_VDITM

Re: How to install and run a script?

2014-10-13 Thread Michael Torrie
On 10/12/2014 08:05 PM, ryguy7272 wrote:
> Ah!!!  I didn't know I needed to run it from the command prompt!  Ok, not 
> it makes sense, and everything works.
> 
> Thanks to all!

You don't have to run python apps from the command line.  Apps that
throw up windows can usually be run by double-clicking the py file in
windows.  But apps that communicate solely on the terminal or console
have to be run in that environment.


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


Re: Need help in pulling SQL query out of log file...

2014-10-13 Thread alex23

On 14/10/2014 11:47 AM, Sagar Deshmukh wrote:

I have a log file which has lot of information like..SQL query.. number of 
records read...records loaded etc..
My requirement is i would like to read the SQL query completly and write it to 
another txt file..


Generally we encourage people to post what they've tried to the list. It 
helps us identify what you know and what you need help with.


However, given:

> the log file may not be always same so can not make static choices...

You'll probably want to use regular expressions:

https://docs.python.org/howto/regex.html

Regexps let you search through the text for known patterns and extract 
any that match. To extract all SQL query sections, you'll need to come 
up with a way of uniquely identifying them from all other sections. 
Looking at your example log file, it looks like they're all of the format:


SQL Query []

From that we can determine that all SQL queries are prefixed by 'SQL 
Query [' and suffixed by ']', so the content you want is everything 
between those markers. So a possible regular expression might be:


SQL Query \[(.*?)\]

To quickly explain this:

1. "SQL Query " matches on that string
2. Because [] have meaning for regexes, to match on literal 
brackets you need to escape them via \[ and \]

3. ( ) is a group, whats contained in here will be returned
4. .* means to grab all matching text
5. ? means to do an "ungreedy" grab ie it'll stop at the first \] 
it encounters.


Pulling the queries out of your log file should be as simple as:

import re

log = open('logfile').read()
queries = re.findall("SQL Query \[(.*?)\]", log, re.DOTALL)

Because the queries can fall across multiple lines, the re.DOTALL flag 
is required to treat EOL markers as characters.


Hope this helps.
--
https://mail.python.org/mailman/listinfo/python-list


Re: TypeError: 'kwarg' is an invalid keyword argument for this function

2014-10-13 Thread alex23

On 13/10/2014 8:04 PM, Dave Angel wrote:

It would also help to spell it the same.  In the OP's
  implementation,  he defined kwargs, and tried to use it as
  kwarg.


That's perfectly okay, though: if `kwargs` is the name used to reference 
the dictionary of keyword arguments, `kwarg` would be an instance of a 
keyword argument.


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


Re: Need help in pulling SQL query out of log file...

2014-10-13 Thread Sagar Deshmukh
On Monday, 13 October 2014 22:40:07 UTC-7, alex23  wrote:
> On 14/10/2014 11:47 AM, Sagar Deshmukh wrote:
> 
> > I have a log file which has lot of information like..SQL query.. number of 
> > records read...records loaded etc..
> 
> > My requirement is i would like to read the SQL query completly and write it 
> > to another txt file..
> 
> 
> 
> Generally we encourage people to post what they've tried to the list. It 
> 
> helps us identify what you know and what you need help with.
> 
> 
> 
> However, given:
> 
> 
> 
>  > the log file may not be always same so can not make static choices...
> 
> 
> 
> You'll probably want to use regular expressions:
> 
> 
> 
>  https://docs.python.org/howto/regex.html
> 
> 
> 
> Regexps let you search through the text for known patterns and extract 
> 
> any that match. To extract all SQL query sections, you'll need to come 
> 
> up with a way of uniquely identifying them from all other sections. 
> 
> Looking at your example log file, it looks like they're all of the format:
> 
> 
> 
>  SQL Query []
> 
> 
> 
>  From that we can determine that all SQL queries are prefixed by 'SQL 
> 
> Query [' and suffixed by ']', so the content you want is everything 
> 
> between those markers. So a possible regular expression might be:
> 
> 
> 
>  SQL Query \[(.*?)\]
> 
> 
> 
> To quickly explain this:
> 
> 
> 
>  1. "SQL Query " matches on that string
> 
>  2. Because [] have meaning for regexes, to match on literal 
> 
> brackets you need to escape them via \[ and \]
> 
>  3. ( ) is a group, whats contained in here will be returned
> 
>  4. .* means to grab all matching text
> 
>  5. ? means to do an "ungreedy" grab ie it'll stop at the first \] 
> 
> it encounters.
> 
> 
> 
> Pulling the queries out of your log file should be as simple as:
> 
> 
> 
>  import re
> 
> 
> 
>  log = open('logfile').read()
> 
>  queries = re.findall("SQL Query \[(.*?)\]", log, re.DOTALL)
> 
> 
> 
> Because the queries can fall across multiple lines, the re.DOTALL flag 
> 
> is required to treat EOL markers as characters.
> 
> 
> 
> Hope this helps.

Hi,

This helps and its working... Thank you so much
-- 
https://mail.python.org/mailman/listinfo/python-list