a problem with importing pygame

2016-04-22 Thread Kiril Bard
I use python for my school work and I wanted to download it at home. I had
my teacher download the version to a flash drive and it still doesn't seem
to work. The version that I got  from the flash drive was python 3.4.2 and
I think I got a 32 bit or a 64 bit pygame  for a windows machine. The
program does not import pygame, it says that there is no module named
pygame.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: delete from pattern to pattern if it contains match

2016-04-22 Thread harirammanohar
On Thursday, April 21, 2016 at 7:03:00 PM UTC+5:30, Jussi Piitulainen wrote:
> harirammano...@gmail.com writes:
> 
> > On Monday, April 18, 2016 at 12:38:03 PM UTC+5:30,
> > hariram...@gmail.com wrote:
> >> HI All,
> >> 
> >> can you help me out in doing below. 
> >> 
> >> file: 
> >>  
> >>  guava 
> >> fruit 
> >>  
> >>  
> >>  mango 
> >> fruit 
> >>  
> >>  
> >>  orange 
> >> fruit 
> >>  
> >> 
> >> need to delete from start to end if it contains mango in a file...
> >> 
> >> output should be: 
> >> 
> >>  
> >>  guava 
> >> fruit 
> >>  
> >>  
> >>  orange 
> >> fruit 
> >>  
> >> 
> >> Thank you
> >
> > any one can guide me ? why xml tree parsing is not working if i have
> > root.tag and root.attrib as mentioned in earlier post...
> 
> Assuming the real consists of lines between a start marker and end
> marker, a winning plan is to collect a group of lines, deal with it, and
> move on.
> 
> The following code implements something close to the plan. You need to
> adapt it a bit to have your own source of lines and to restore the end
> marker in the output and to account for your real use case and for
> differences in taste and judgment. - The plan is as described above, but
> there are many ways to implement it.
> 
> from io import StringIO
> 
> text = '''\
>  
>   guava 
> fruit 
>  
> 
>   mango
> fruit
> 
>  
>   orange 
> fruit 
>  
> '''
> 
> def records(source):
> current = []
> for line in source:
> if line.startswith(''):
> yield current
> current = []
> else:
> current.append(line)
> 
> def hasmango(record):
> return any('mango' in it for it in record)
> 
> for record in records(StringIO(text)):
> hasmango(record) or print(*record)

Hi,

not workingthis is the output i am getting...

\
 
   guava
 fruit


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


Re: delete from pattern to pattern if it contains match

2016-04-22 Thread harirammanohar
On Thursday, April 21, 2016 at 4:55:18 PM UTC+5:30, Peter Otten wrote:
> harirammano...@gmail.com wrote:
> 
> > On Monday, April 18, 2016 at 12:38:03 PM UTC+5:30, hariram...@gmail.com
> > wrote:
> >> HI All,
> >> 
> >> can you help me out in doing below.
> >> 
> >> file:
> >> 
> >>  guava
> >> fruit
> >> 
> >> 
> >>  mango
> >> fruit
> >> 
> >> 
> >>  orange
> >> fruit
> >> 
> 
> Is that literally what you have in the file?
> 
> > any one can guide me ? why xml tree parsing is not working if i have
> > root.tag and root.attrib as mentioned in earlier post...
> 
> The data above is not valid xml. Instead of
> 
> ...
> 
> you need
> 
> ...
> 
> i. e. the end tag must be the same as the start tag, but with a leading "/".

@peter yes here it is not xml, but real data is an xml..believe me..
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: delete from pattern to pattern if it contains match

2016-04-22 Thread harirammanohar
On Friday, April 22, 2016 at 2:30:45 PM UTC+5:30, hariram...@gmail.com wrote:
> On Thursday, April 21, 2016 at 4:55:18 PM UTC+5:30, Peter Otten wrote:
> > harirammano...@gmail.com wrote:
> > 
> > > On Monday, April 18, 2016 at 12:38:03 PM UTC+5:30, hariram...@gmail.com
> > > wrote:
> > >> HI All,
> > >> 
> > >> can you help me out in doing below.
> > >> 
> > >> file:
> > >> 
> > >>  guava
> > >> fruit
> > >> 
> > >> 
> > >>  mango
> > >> fruit
> > >> 
> > >> 
> > >>  orange
> > >> fruit
> > >> 
> > 
> > Is that literally what you have in the file?
> > 
> > > any one can guide me ? why xml tree parsing is not working if i have
> > > root.tag and root.attrib as mentioned in earlier post...
> > 
> > The data above is not valid xml. Instead of
> > 
> > ...
> > 
> > you need
> > 
> > ...
> > 
> > i. e. the end tag must be the same as the start tag, but with a leading "/".
> 
> @peter yes here it is not xml, but real data is an xml..believe me..

@peter this is the similar xml i am having, you can correlate.

https://tomcat.apache.org/tomcat-5.5-doc/appdev/web.xml.txt
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: delete from pattern to pattern if it contains match

2016-04-22 Thread Peter Otten
harirammano...@gmail.com wrote:

> On Thursday, April 21, 2016 at 7:03:00 PM UTC+5:30, Jussi Piitulainen
> wrote:
>> harirammano...@gmail.com writes:
>> 
>> > On Monday, April 18, 2016 at 12:38:03 PM UTC+5:30,
>> > hariram...@gmail.com wrote:
>> >> HI All,
>> >> 
>> >> can you help me out in doing below.
>> >> 
>> >> file:
>> >> 
>> >>  guava
>> >> fruit
>> >> 
>> >> 
>> >>  mango
>> >> fruit
>> >> 
>> >> 
>> >>  orange
>> >> fruit
>> >> 
>> >> 
>> >> need to delete from start to end if it contains mango in a file...
>> >> 
>> >> output should be:
>> >> 
>> >> 
>> >>  guava
>> >> fruit
>> >> 
>> >> 
>> >>  orange
>> >> fruit
>> >> 
>> >> 
>> >> Thank you
>> >
>> > any one can guide me ? why xml tree parsing is not working if i have
>> > root.tag and root.attrib as mentioned in earlier post...
>> 
>> Assuming the real consists of lines between a start marker and end
>> marker, a winning plan is to collect a group of lines, deal with it, and
>> move on.
>> 
>> The following code implements something close to the plan. You need to
>> adapt it a bit to have your own source of lines and to restore the end
>> marker in the output and to account for your real use case and for
>> differences in taste and judgment. - The plan is as described above, but
>> there are many ways to implement it.
>> 
>> from io import StringIO
>> 
>> text = '''\
>> 
>>   guava
>> fruit
>> 
>> 
>>   mango
>> fruit
>> 
>> 
>>   orange
>> fruit
>> 
>> '''
>> 
>> def records(source):
>> current = []
>> for line in source:
>> if line.startswith(''):
>> yield current
>> current = []
>> else:
>> current.append(line)
>> 
>> def hasmango(record):
>> return any('mango' in it for it in record)
>> 
>> for record in records(StringIO(text)):
>> hasmango(record) or print(*record)
> 
> Hi,
> 
> not workingthis is the output i am getting...
> 
> \

This means that the line

>> text = '''\

has trailing whitespace in your copy of the script.

>  
>guava
>  fruit
> 
> 
>orange
>  fruit

Jussi forgot to add the "..." line to the group. To fix this change the 
generator to

def records(source):
current = []
for line in source:
current.append(line)
if line.startswith(''):
yield current
current = []


>> hasmango(record) or print(*record)

The

print(*record)

inserts spaces between record entries (i. e. at the beginning of all lines 
except the first) and adds a trailing newline. You can avoid this by 
specifying the delimiters explicitly:

if not hasmango(record):
print(*record, sep="", end="")

Even with these changes code still looks somewhat brittle...

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


Re: delete from pattern to pattern if it contains match

2016-04-22 Thread Peter Otten
harirammano...@gmail.com wrote:

>> @peter yes here it is not xml, but real data is an xml..believe me..
> 
> @peter this is the similar xml i am having, you can correlate.
> 
> https://tomcat.apache.org/tomcat-5.5-doc/appdev/web.xml.txt

This is still too vague.

If you post the code you actually tried in a small standalone script 
together with a small sample xml file that produces the same failure as your 
actual data I or someone might help you fix it.

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


Re: delete from pattern to pattern if it contains match

2016-04-22 Thread Jussi Piitulainen
Peter Otten writes:

> harirammano...@gmail.com wrote:
>
>> On Thursday, April 21, 2016 at 7:03:00 PM UTC+5:30, Jussi Piitulainen
>> wrote:
>>> harirammano...@gmail.com writes:
>>> 
>>> > On Monday, April 18, 2016 at 12:38:03 PM UTC+5:30,
>>> > hariram...@gmail.com wrote:
>>> >> HI All,
>>> >> 
>>> >> can you help me out in doing below.
>>> >> 
>>> >> file:
>>> >> 
>>> >>  guava
>>> >> fruit
>>> >> 
>>> >> 
>>> >>  mango
>>> >> fruit
>>> >> 
>>> >> 
>>> >>  orange
>>> >> fruit
>>> >> 
>>> >> 
>>> >> need to delete from start to end if it contains mango in a file...
>>> >> 
>>> >> output should be:
>>> >> 
>>> >> 
>>> >>  guava
>>> >> fruit
>>> >> 
>>> >> 
>>> >>  orange
>>> >> fruit
>>> >> 
>>> >> 
>>> >> Thank you
>>> >
>>> > any one can guide me ? why xml tree parsing is not working if i have
>>> > root.tag and root.attrib as mentioned in earlier post...
>>> 
>>> Assuming the real consists of lines between a start marker and end
>>> marker, a winning plan is to collect a group of lines, deal with it, and
>>> move on.
>>> 
>>> The following code implements something close to the plan. You need to
>>> adapt it a bit to have your own source of lines and to restore the end
>>> marker in the output and to account for your real use case and for
>>> differences in taste and judgment. - The plan is as described above, but
>>> there are many ways to implement it.
>>> 
>>> from io import StringIO
>>> 
>>> text = '''\
>>> 
>>>   guava
>>> fruit
>>> 
>>> 
>>>   mango
>>> fruit
>>> 
>>> 
>>>   orange
>>> fruit
>>> 
>>> '''
>>> 
>>> def records(source):
>>> current = []
>>> for line in source:
>>> if line.startswith(''):
>>> yield current
>>> current = []
>>> else:
>>> current.append(line)
>>> 
>>> def hasmango(record):
>>> return any('mango' in it for it in record)
>>> 
>>> for record in records(StringIO(text)):
>>> hasmango(record) or print(*record)
>> 
>> Hi,
>> 
>> not workingthis is the output i am getting...
>> 
>> \
>
> This means that the line
>
>>> text = '''\
>
> has trailing whitespace in your copy of the script.

That's a nuisance. I wish otherwise undefined escape sequences in
strings raised an error, similar to a stray space after a line
continuation character.

>>  
>>guava
>>  fruit
>> 
>> 
>>orange
>>  fruit
>
> Jussi forgot to add the "..." line to the group.

I didn't forget. I meant what I said when I said the OP needs to adapt
the code to (among other things) restore the end marker in the output.
If they can't be bothered to do anything at all, it's their problem.

It was already known that this is not the actual format of the data.

> To fix this change the generator to
>
> def records(source):
> current = []
> for line in source:
> current.append(line)
> if line.startswith(''):
> yield current
> current = []

Oops, I notice that I forgot to start a new record only on encountering
a '' line. That should probably be done, unless the format is
intended to be exactly a sequence of "\n- -\n\n".

>>> hasmango(record) or print(*record)
>
> The
>
> print(*record)
>
> inserts spaces between record entries (i. e. at the beginning of all
> lines except the first) and adds a trailing newline.

Yes, I forgot about the space. Sorry about that.

The final newline was intentional. Perhaps I should have added the end
marker there instead (given my preference to not drag it together with
the data lines), like so:

   print(*record, sep = "", end = "\n")

Or so:

   print(*record, sep = "")
   print("")

Or so:

   for line in record:
   print(line.rstrip("\n")
   else:
   print("")

Or:

   for line in record:
   print(line.rstrip("\n")
   else:
   if record and not record[-1].strip() == "":
   print("")

But all this is beside the point that to deal with the stated problem
one might want to obtain access to a whole record *first*, then check if
it contains "mango" in the intended way (details missing but at least
"mango\n" as a full line counts as an occurrence), and only *then* print
the whole record (if it doesn't contain "mango").

I can think of two other ways - one if the data can be accessed only
once - but they seem more complicated to me. Hm, well, if it's XML, as
stated in another branch of this thread and contrary to the form of the
example data in this branch, there's a third way that may be good, but
here I'm responding to a line-oriented format.

> You can avoid this by specifying the delimiters explicitly:
>
> if not hasmango(record):
> print(*record, sep="", end="")
>
> Even with these changes code still looks somewhat brittle...

That depends on the actual data format, and on what really is intended
to trigger the filter. This approach is a complete waste of effort if
there are no guarantees of things being there on their own lines, for
example.

Ok, that "\ " not only looks brittle but actually is brittle. The one
time I used that slash, 

Re: Running lpr on windows from python

2016-04-22 Thread loial
Nothing seems to work.

Even doing

import os
os.system("lpr")

still returns 
'lpr' is not recognized as an internal or external command,operable program or 
batch file.


Even though I can run lpr fine from the command prompt

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


Re: a problem with importing pygame

2016-04-22 Thread Tim Golden
On 22/04/2016 09:07, Kiril Bard wrote:
> I use python for my school work and I wanted to download it at home. I had
> my teacher download the version to a flash drive and it still doesn't seem
> to work. The version that I got  from the flash drive was python 3.4.2 and
> I think I got a 32 bit or a 64 bit pygame  for a windows machine. The
> program does not import pygame, it says that there is no module named
> pygame.
> 

Kiril.

Your description of the  problem isn't quite clear. If you haven't, I
suggest you:

* Download Python 3.4 from here:

https://www.python.org/downloads/release/python-343/

(Either the "Windows x86-64 MSI installer" or the "Windows x86 MSI
installer" depending on whether you want 64 or 32-bit respectively)

Run the installer and accept the defaults (unless you have a clear
reason to do otherwise)

* Then download the corresponding version of Pygame from here:

https://bitbucket.org/pygame/pygame/downloads

Either:

https://bitbucket.org/pygame/pygame/downloads/pygame-1.9.2a0-hg_ea3b3bb8714a.win32-py3.4.msi

for 32-bit; or

https://bitbucket.org/pygame/pygame/downloads/pygame-1.9.2a0-hg_8d9e6a1f2635+.win-amd64-py3.4.msi

for 64-bit

Run the installer and accept the defaults

* Then you should be able to start Python and import pygame

If you still have problems, please post back here to see if we can help you.

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


Re: help

2016-04-22 Thread vittorio maria iacullo
Done! Thank you!

2016-04-22 12:57 GMT+02:00 vittorio maria iacullo :

> Hi
> I've just installed on my laptop python 3.5.1
>
> but I get a error message. I alredy ran the "repair session". May you tell
> me please what should I do?
>
> Best,
>
> --
>
>
> *Vittorio Maria Iacullo​*
>



-- 
*Vittorio Maria Iacullo*
-- 
https://mail.python.org/mailman/listinfo/python-list


Can't run lpr from python on windows 2012 server

2016-04-22 Thread loial
I am reposting this question in a simpler form.

I can run lpr from the command prompt but not from python

os.system("notepad") works
os.system("lpr") does not work. Basically it says lpr is not a known program or 
executable

Why can I run lpr from the windows command prompt but not from python(2.7)

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


Re: Can't run lpr from python on windows 2012 server

2016-04-22 Thread Random832
On Fri, Apr 22, 2016, at 10:15, loial wrote:
> I am reposting this question in a simpler form.
> 
> I can run lpr from the command prompt but not from python
> 
> os.system("notepad") works
> os.system("lpr") does not work. Basically it says lpr is not a known
> program or executable
> 
> Why can I run lpr from the windows command prompt but not from
> python(2.7)

Does lpr.exe actually physically exist in c:\windows\system32 as you
have indicated in the your earlier posts? I.e. if you actually browse
system32 with the file manager will you see lpr.exe? The problem with
your question is that it's not a standard command, so none of the rest
of us have it, which means we're half-blind trying to find your problem.
-- 
https://mail.python.org/mailman/listinfo/python-list


Remove directory tree without following symlinks

2016-04-22 Thread Steven D'Aprano
I want to remove a directory, including all files and subdirectories under
it, but without following symlinks. I want the symlinks to be deleted, not
the files pointed to by those symlinks.

E.g. if I have this tree:


parent/
+-- spam/
:   +-- a.txt
:   +-- b.txt
:   +-- eggs/
:   :   +-- c.txt
:   :   +-- surprise -> ../../parent
:   +-- d.txt
+-- e.txt

and I call remove_tree("parent/spam"), I want the result to be:

parent/
+-- e.txt


(Assuming that I have permission to delete all the files and directories.)

What should I use for "remove_tree"? Do I have to write my own, or does a
solution already exist?




-- 
Steven

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


Re: Detecting repeated subsequences of identical items

2016-04-22 Thread Steven D'Aprano
On Fri, 22 Apr 2016 12:12 am, Chris Angelico wrote:

> On Fri, Apr 22, 2016 at 12:01 AM, Oscar Benjamin
>  wrote:
>> In the recursive stack overflow case what you'll usually have is
>>
>> 1) A few frames leading up to the start of recursion
>> 2) A long repetitive sequence of frames
>> 3) A few frames at the end showing how the exception was ultimately
>> triggered.
>>
>> You just need to find the cycle that makes that big long sequence.

I am not convinced that it is a cycle in the technical sense, or that the
two algorithms that Oscar linked to will necessarily find them. They may,
by chance, happen to find them sometimes, but the way the algorithms work
is by detecting periodic behaviour, and this is not periodic.

Look at the comment for Floyd's algorithm here:

https://en.wikipedia.org/wiki/Cycle_detection

# The hare moves twice as quickly as the tortoise and
# the distance between them increases by 1 at each step.
# Eventually they will both be inside the cycle and then, ...


but that is violated in this scenario. The hare can escape the (non-)cycle
before the tortoise even enters it. Even if both enter the "cycle", there's
no guarantee that the termination condition `tortoise == hare` will ever be
true because the cycle doesn't loop and doesn't go back to the beginning.
Hence it is not a cycle.

 
> If the stack got overflowed, there won't usually be a part 3, as part 
> 2 is the bit that hits sys.recursionlimit (unless increasing the
> recursion limit by a finite number would solve the problem). 

Don't just think of breaking the recursion limit. You might be 100 calls
deep in some complex chain of function calls when something raises
ValueError. In principle, there might not even be any recursive calls at
all.


-- 
Steven

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


Re: Remove directory tree without following symlinks

2016-04-22 Thread Random832
On Fri, Apr 22, 2016, at 10:56, Steven D'Aprano wrote:
> What should I use for "remove_tree"? Do I have to write my own, or does a
> solution already exist?

In the os.walk documentation it provides a simple recipe and also
mentions shutil.rmtree
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Running lpr on windows from python

2016-04-22 Thread loial
I finally found the solution here :

http://www.tomshardware.co.uk/forum/240019-44-error-windows

Copied lpr.exe, lprhelp.dll, and lprmonui.dll from the System32 folder to the 
sysWOW64 folder

Thanks for all your efforts
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can't run lpr from python on windows 2012 server

2016-04-22 Thread loial
Yes it does. I finally found the solution here :

http://www.tomshardware.co.uk/forum/240019-44-error-windows

Copied lpr.exe, lprhelp.dll, and lprmonui.dll from the System32 folder to the 
sysWOW64 folder




On Friday, April 22, 2016 at 3:27:18 PM UTC+1, Random832 wrote:
> On Fri, Apr 22, 2016, at 10:15, loial wrote:
> > I am reposting this question in a simpler form.
> > 
> > I can run lpr from the command prompt but not from python
> > 
> > os.system("notepad") works
> > os.system("lpr") does not work. Basically it says lpr is not a known
> > program or executable
> > 
> > Why can I run lpr from the windows command prompt but not from
> > python(2.7)
> 
> Does lpr.exe actually physically exist in c:\windows\system32 as you
> have indicated in the your earlier posts? I.e. if you actually browse
> system32 with the file manager will you see lpr.exe? The problem with
> your question is that it's not a standard command, so none of the rest
> of us have it, which means we're half-blind trying to find your problem.

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


Re: Can't run lpr from python on windows 2012 server

2016-04-22 Thread Random832
On Fri, Apr 22, 2016, at 11:06, loial wrote:
> Yes it does. I finally found the solution here :
> 
> http://www.tomshardware.co.uk/forum/240019-44-error-windows
> 
> Copied lpr.exe, lprhelp.dll, and lprmonui.dll from the System32 folder to
> the sysWOW64 folder

A better solution might be to install a 64-bit version of Python.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A pickle problem!

2016-04-22 Thread Ian Kelly
On Thu, Apr 21, 2016 at 7:52 PM, Paulo da Silva
 wrote:
> Às 22:43 de 21-04-2016, Paulo da Silva escreveu:
>> Hi.
>>
>> Why in this code fragment self.__name is not kept between pickle
>> dumps/loads? How to fix it?
>>
>> Thanks.
>>
>> import pickle
>> import pandas as pd
>> import numpy as np
>>
>> class C(pd.DataFrame):
>>   def __init__(self,name,*a,**b):
>>   super(C,self).__init__(*a,**b)
>>   self.__name=name
>>
>>   def GetName(self):
>>   return self.__name
>>
> # Adding this works but looks tricky!
>
> def __getstate__(self):
> dfstate=super(C,self).__getstate__()
> cstate=(dfstate,self.__name)
> return cstate
>
> def __setstate__(self,cstate):
> super(C,self).__setstate__(cstate[0])
> self.__name=cstate[1]

Probably this is necessary because the DataFrame class is already
customizing its pickle behavior without taking into account the
possibility of added attributes by subclasses. I think that your
solution of wrapping the state of the superclass looks fine.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Running lpr on windows from python

2016-04-22 Thread eryk sun
On Fri, Apr 22, 2016 at 10:07 AM, loial  wrote:
> I finally found the solution here :
>
> http://www.tomshardware.co.uk/forum/240019-44-error-windows
>
> Copied lpr.exe, lprhelp.dll, and lprmonui.dll from the System32 folder to the 
> sysWOW64 folder

Using the virtual "SysNative" directory should work on Windows 7+
(Server 2008 R2). All you need is for CreateProcess to find the
executable. Finding the DLLs is done during process initialization, so
there's no need to copy them from the native System32 directory.

It works for me in 32-bit Python running in Windows 10:

>>> if '32bit' in platform.architecture():
... lpr = os.path.join(os.environ['SystemRoot'], 'SysNative', 'lpr.exe')
... else:
... lpr = os.path.join(os.environ['SystemRoot'], 'System32', 'lpr.exe')
...
>>> print(lpr)
C:\Windows\SysNative\lpr.exe
>>> subprocess.call(lpr)

Sends a print job to a network printer

Usage: lpr -S server -P printer [-C class] [-J job] [-o option]
[-x] [-d] filename

Options:
  -S serverName or ipaddress of the host providing lpd service
  -P printer   Name of the print queue
  -C class Job classification for use on the burst page
  -J job   Job name to print on the burst page
  -o optionIndicates type of the file (by default assumes
a text file)
   Use "-o l" for binary (e.g. postscript) files
  -x   Compatibility with SunOS 4.1.x and prior
  -d   Send data file first1
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can't run lpr from python on windows 2012 server

2016-04-22 Thread eryk sun
On Fri, Apr 22, 2016 at 9:26 AM, Random832  wrote:
> The problem with your question is that it's not a standard command, so none
> of the rest of us have it, which means we're half-blind trying to find your 
> problem.

lpr is a Windows feature that you may be able to enable. It's under
"Print and Document Services" -> "LPR Port Monitor". It only installs
a 64-bit build, which is why loial is having trouble running it from
32-bit Python. But in Windows 7+ (Server 2008 R2), a 32-bit process
can use the virtual "%SystemRoot%\SysNative" directory to access files
in the native System32 directory. I can run lpr.exe from 32-bit Python
using this method.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Remove directory tree without following symlinks

2016-04-22 Thread Steven D'Aprano
On Sat, 23 Apr 2016 01:09 am, Random832 wrote:

> On Fri, Apr 22, 2016, at 10:56, Steven D'Aprano wrote:
>> What should I use for "remove_tree"? Do I have to write my own, or does a
>> solution already exist?
> 
> In the os.walk documentation it provides a simple recipe and also
> mentions shutil.rmtree

Thanks for that.

The os.walk recipe is described as a simple version of shutil.rmtree. The
documentation for rmtree seems lacking to me, but after testing it, it
appears to work as I want it: it removes symbolic links, it does not follow
them.

Is anyone else able to confirm that my understanding is correct? If so, the
documentation should probably be a bit clearer.



-- 
Steven

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


RE: Remove directory tree without following symlinks

2016-04-22 Thread Albert-Jan Roskam


> From: st...@pearwood.info
> Subject: Re: Remove directory tree without following symlinks
> Date: Sat, 23 Apr 2016 03:14:12 +1000
> To: python-list@python.org
> 
> On Sat, 23 Apr 2016 01:09 am, Random832 wrote:
> 
> > On Fri, Apr 22, 2016, at 10:56, Steven D'Aprano wrote:
> >> What should I use for "remove_tree"? Do I have to write my own, or does a
> >> solution already exist?
> > 
> > In the os.walk documentation it provides a simple recipe and also
> > mentions shutil.rmtree
> 
> Thanks for that.

FYI, Just today I found out that shutil.rmtree raises a WindowsError if the dir 
is read-only (or its contents). Using 'ignore_errors', won't help. Sure, no 
error is raised, but the dir is not deleted either! A 'force' option would be a 
nice improvement.



> The os.walk recipe is described as a simple version of shutil.rmtree. The
> documentation for rmtree seems lacking to me, but after testing it, it
> appears to work as I want it: it removes symbolic links, it does not follow
> them.
>
> Is anyone else able to confirm that my understanding is correct? If so, the
> documentation should probably be a bit clearer.
> 
> 
> 
> -- 
> Steven
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list
  
-- 
https://mail.python.org/mailman/listinfo/python-list


dbf remove fields.

2016-04-22 Thread Ricardo Aguilar
Hi there i try to remove to fields in dbf table, how I can remove two
fields? 

 

I wanna to remove because I have this error "ValueError: could not convert
string to float: "  But I no need this field.

 

How I can remove this fields o ignore this ValueError? Any advice.

 

Ricardo Alfonso Aguilar Pineda - ragui...@churchs.com.mx
Depto. Sistemas 
867 711-5151 ext. 136

867 119 6506

 

 

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


Re: dbf remove fields.

2016-04-22 Thread Ethan Furman

On 04/22/2016 10:34 AM, Ricardo Aguilar wrote:


Hi there i try to remove to fields in dbf table, how I can remove two
fields?

I wanna to remove because I have this error "ValueError: could not convert
string to float: "  But I no need this field.


Have you tried my dbf package?

  https://pypi.python.org/pypi/dbf

I'm pretty sure it handles such values.

--
~Ethan~

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


Re: Remove directory tree without following symlinks

2016-04-22 Thread eryk sun
On Fri, Apr 22, 2016 at 12:39 PM, Albert-Jan Roskam
 wrote:
> FYI, Just today I found out that shutil.rmtree raises a WindowsError if the 
> dir is read-
> only (or its contents). Using 'ignore_errors', won't help. Sure, no error is 
> raised, but the
> dir is not deleted either! A 'force' option would be a nice improvement.

Use the onerror handler to call os.chmod(path, stat.S_IWRITE). For
example, see pip's rmtree_errorhandler:

https://github.com/pypa/pip/blob/8.1.1/pip/utils/__init__.py#L105
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: dbf remove fields.

2016-04-22 Thread Ethan Furman

On 04/22/2016 11:28 AM, Ethan Furman wrote:

On 04/22/2016 10:34 AM, Ricardo Aguilar wrote:


Hi there i try to remove to fields in dbf table, how I can remove two
fields?

I wanna to remove because I have this error "ValueError: could not
convert
string to float: "  But I no need this field.


Have you tried my dbf package?

   https://pypi.python.org/pypi/dbf

I'm pretty sure it handles such values.


Yup, just checked -- it transforms invalid  values to None.  Since 
you're not using those fields that won't be a problem (otherwise you 
would have filter them out).


--
~Ethan~

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


Re: A pickle problem!

2016-04-22 Thread Paulo da Silva
Às 17:27 de 22-04-2016, Ian Kelly escreveu:
> On Thu, Apr 21, 2016 at 7:52 PM, Paulo da Silva
>  wrote:
>> Às 22:43 de 21-04-2016, Paulo da Silva escreveu:
...

> 
> Probably this is necessary because the DataFrame class is already
> customizing its pickle behavior without taking into account the
> possibility of added attributes by subclasses. I think that your
> solution of wrapping the state of the superclass looks fine.
> 
Thank you.

For any other vars ...
Is there a way to get the vars of only the derived class?

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


Re: A pickle problem!

2016-04-22 Thread Ian Kelly
On Fri, Apr 22, 2016 at 2:21 PM, Paulo da Silva
 wrote:
> Às 17:27 de 22-04-2016, Ian Kelly escreveu:
>> On Thu, Apr 21, 2016 at 7:52 PM, Paulo da Silva
>>  wrote:
>>> Às 22:43 de 21-04-2016, Paulo da Silva escreveu:
> ...
>
>>
>> Probably this is necessary because the DataFrame class is already
>> customizing its pickle behavior without taking into account the
>> possibility of added attributes by subclasses. I think that your
>> solution of wrapping the state of the superclass looks fine.
>>
> Thank you.
>
> For any other vars ...
> Is there a way to get the vars of only the derived class?

If they start with two underscores then you could use the name
mangling to find them. If the class name is MyClass then look for any
keys in the instance dict that start with '_MyClass__'. Otherwise no,
you'd have to list them explicitly.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How much sanity checking is required for function inputs?

2016-04-22 Thread Michael Selik
On Fri, Apr 22, 2016, 1:26 AM Stephen Hansen  wrote:

> On Thu, Apr 21, 2016, at 08:33 PM, Christopher Reimer wrote:
> > On 4/21/2016 7:20 PM, Stephen Hansen wrote:
> > > I... that... what... I'd forget that link and pretend you never went
> > > there. Its not helpful.
> >
> > I found it on the Internet, so it must be true -- and Pythonic at that!
>
> My advice is to not look at that site further. I can't count the number
> of things that are just... not useful or helpful.
>
> Directly translating the Gang of Four Design Pattern book to Python
> doesn't generally result in useful ideas, except in certain abstractions
> like the visitor pattern when you're designing big systems.
>

Frankly, for someone coming from Java, the best advice is to not write any
classes until you must. Of course classes in Python are very useful. It's
just that your Java habits are unnecessary and often counter-productive.

Just make some globals and some functions. Heck, even write procedurally
for a while. Free yourself from the Kingdom of Nouns.
http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html

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


Re: A pickle problem!

2016-04-22 Thread Paulo da Silva
Às 21:33 de 22-04-2016, Ian Kelly escreveu:
> On Fri, Apr 22, 2016 at 2:21 PM, Paulo da Silva
>  wrote:
...
> 
> If they start with two underscores then you could use the name
> mangling to find them. If the class name is MyClass then look for any
> keys in the instance dict that start with '_MyClass__'. Otherwise no,
> you'd have to list them explicitly.
> 
OK, thanks.

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


Re: how to setup for localhost:8000

2016-04-22 Thread wrh8609
On Sunday, April 17, 2016 at 1:11:39 PM UTC-4, Pierre Quentel wrote:
> > > 127.0.0.1 - - [15/Apr/2016 20:57:32] "GET / HTTP/1.1" 200 -
> >  Hi Pierre,
> > 
> > When I type http://localhost:8000, I did not see anything in the console 
> > after the line "Serving HTTP on 0.0.0.0 port 8000 ... I believe the way I 
> > ran was not correct as shown below:
> > > python -m http.server 
> > Serving HTTP on 0.0.0.0 port 8000 ...
> > 
> > Also if I use internet Explorer, it shows HTTP 404 errors.
> > Do you think the way I am doing of the localhost:8000 setting was not 
> > correct?
> > 
> > Thanks,
> > Wen-Ruey
> 
> If you're not seeing anything there, it is sure that the Python server 
> doesn't serve requests on port 8000. But if you're seeing a blank screen or a 
> 404 error instead of a message saying that a connection couldn't be set up, 
> it is likely that another HTTP server is running on your machine on port 8000.
> 
> Could you try to start the server on another port, eg "python -m http.server 
> 8085" and see what happens in the browser with "http://127.0.0.1:8085"; ?

I followed your instruction but the page shows:
The 127.0.0.1 page isn't working

127.0.0.1 didn't send any data.
ERR_EMPTY_RESPONSE

and a lot of messages show on the command window..

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