Re: .py to .html generation
In a message of Wed, 02 Sep 2015 22:04:03 -0700, [email protected] writes: >Hi friends! > >Can some one help me with the best module and/or its tutorial, to generate >html reports for python scripts? > >I tried pyreport and sphc; but, i am getting errors. >-- >https://mail.python.org/mailman/listinfo/python-list Whenever I want to generate html, I use sphinx. http://sphinx-doc.org/ It has great documentation. http://sphinx-doc.org/contents.html There is a mini-tutorial in there. http://sphinx-doc.org/tutorial.html There is also a report generator implemented as an extension to sphinx. https://github.com/AndreasHeger/CGATReport Interfaces nicely with ipython. Makes it easy to stick matplotlib graphs into your report. HTH, Laura -- https://mail.python.org/mailman/listinfo/python-list
Re: .py to .html generation
In a message of Thu, 03 Sep 2015 09:22:27 +0200, Laura Creighton writes: >There is also a report generator implemented as an extension to sphinx. >https://github.com/AndreasHeger/CGATReport >Interfaces nicely with ipython. Makes it easy to stick matplotlib >graphs into your report. I forgot about the 'searching on pip is temporarily broken problem' yes, there is a pip packagex for this, you do not have to get it from source. https://pypi.python.org/pypi/SphinxReport Laura -- https://mail.python.org/mailman/listinfo/python-list
Re: Reading \n unescaped from a file
On 09/02/2015 04:03 AM, Rob Hills wrote:
Hi,
I am developing code (Python 3.4) that transforms text data from one
format to another.
As part of the process, I had a set of hard-coded str.replace(...)
functions that I used to clean up the incoming text into the desired
output format, something like this:
dataIn = dataIn.replace('\r', '\\n') # Tidy up linefeeds
dataIn = dataIn.replace('<','<') # Tidy up < character
dataIn = dataIn.replace('>','>') # Tidy up < character
dataIn = dataIn.replace('o','o') # No idea why but lots of these:
convert to 'o' character
dataIn = dataIn.replace('f','f') # .. and these: convert to 'f'
character
dataIn = dataIn.replace('e','e') # .. 'e'
dataIn = dataIn.replace('O','O') # .. 'O'
These statements transform my data correctly, but the list of statements
grows as I test the data so I thought it made sense to store the
replacement mappings in a file, read them into a dict and loop through
that to do the cleaning up, like this:
with open(fileName, 'r+t', encoding='utf-8') as mapFile:
for line in mapFile:
line = line.strip()
try:
if (line) and not line.startswith('#'):
line = line.split('#')[:1][0].strip() # trim any
trailing comments
name, value = line.split('=')
name = name.strip()
self.filterMap[name]=value.strip()
except:
self.logger.error('exception occurred parsing line [{0}]
in file [{1}]'.format(line, fileName))
raise
Elsewhere, I use the following code to do the actual cleaning up:
def filter(self, dataIn):
if dataIn:
for token, replacement in self.filterMap.items():
dataIn = dataIn.replace(token, replacement)
return dataIn
My mapping file contents look like this:
\r = \\n
â = "
< = <
> = >
' = '
F = F
o = o
f = f
e = e
O = O
This all works "as advertised" */except/* for the '\r' => '\\n'
replacement. Debugging the code, I see that my '\r' character is
"escaped" to '\\r' and the '\\n' to 'n' when they are read in from
the file.
I've been googling hard and reading the Python docs, trying to get my
head around character encoding, but I just can't figure out how to get
these bits of code to do what I want.
It seems to me that I need to either:
* change the way I represent '\r' and '\\n' in my mapping file; or
* transform them somehow when I read them in
However, I haven't figured out how to do either of these.
TIA,
I have had this problem too and can propose a solution ready to run out
of my toolbox:
class editor:
def compile (self, replacements):
targets, substitutes = zip (*replacements)
re_targets = [re.escape (item) for item in targets]
re_targets.sort (reverse = True)
self.targets_set = set (targets)
self.table = dict (replacements)
regex_string = '|'.join (re_targets)
self.regex = re.compile (regex_string, re.DOTALL)
def edit (self, text, eat = False):
hits = self.regex.findall (text)
nohits = self.regex.split (text)
valid_hits = set (hits) & self.targets_set # Ignore targets
with illegal re modifiers.
if valid_hits:
substitutes = [self.table [item] for item in hits if item
in valid_hits] + [] # Make lengths equal for zip to work right
if eat:
output = ''.join (substitutes)
else:
zipped = zip (nohits, substitutes)
output = ''.join (list (reduce (lambda a, b: a + b,
[zipped][0]))) + nohits [-1]
else:
if eat:
output = ''
else:
output = input
return output
>>> substitutions = (
('\r', '\n'),
('<', '<'),
('>', '>'),
('o', 'o'),
('f', 'f'),
('e', 'e'),
('O', 'O'),
)
Order doesn't matter. Add new ones at the end.
>>> e = editor ()
>>> e.compile (substitutions)
A simple way of testing is running the substitutions through the editor
>>> print e.edit (repr (substitutions))
(('\r', '\n'), ('<', '<'), ('>', '>'), ('o', 'o'), ('f', 'f'), ('e',
'e'), ('O', 'O'))
The escapes need to be tested separately
>>> print e.edit ('abc\rdef')
abc
def
Note: This editor's compiler compiles the substitution list to a regular
expression which the editor uses to find all matches in the text passed
to edit. There has got to be a limit to the size of a text which a
regular expression can handle. I don't know what this limit is. To be on
the safe side, edit a large text line by line or at least in sensible
chunks.
Frederic
--
https://mail.python.org/mailman/listinfo/python-list
Re: Reading \n unescaped from a file
Friedrich Rentsch wrote:
>
>
> On 09/02/2015 04:03 AM, Rob Hills wrote:
>> Hi,
>>
>> I am developing code (Python 3.4) that transforms text data from one
>> format to another.
>>
>> As part of the process, I had a set of hard-coded str.replace(...)
>> functions that I used to clean up the incoming text into the desired
>> output format, something like this:
>>
>> dataIn = dataIn.replace('\r', '\\n') # Tidy up linefeeds
>> dataIn = dataIn.replace('<','<') # Tidy up < character
>> dataIn = dataIn.replace('>','>') # Tidy up < character
>> dataIn = dataIn.replace('o','o') # No idea why but lots of
>> these: convert to 'o' character dataIn =
>> dataIn.replace('f','f') # .. and these: convert to 'f'
>> character
>> dataIn = dataIn.replace('e','e') # .. 'e'
>> dataIn = dataIn.replace('O','O') # .. 'O'
>>
>> These statements transform my data correctly, but the list of statements
>> grows as I test the data so I thought it made sense to store the
>> replacement mappings in a file, read them into a dict and loop through
>> that to do the cleaning up, like this:
>>
>> with open(fileName, 'r+t', encoding='utf-8') as mapFile:
>> for line in mapFile:
>> line = line.strip()
>> try:
>> if (line) and not line.startswith('#'):
>> line = line.split('#')[:1][0].strip() # trim any
>> trailing comments name, value = line.split('=')
>> name = name.strip()
>> self.filterMap[name]=value.strip()
>> except:
>> self.logger.error('exception occurred parsing line
>> [{0}] in file [{1}]'.format(line, fileName)) raise
>>
>> Elsewhere, I use the following code to do the actual cleaning up:
>>
>> def filter(self, dataIn):
>> if dataIn:
>> for token, replacement in self.filterMap.items():
>> dataIn = dataIn.replace(token, replacement)
>> return dataIn
>>
>>
>> My mapping file contents look like this:
>>
>> \r = \\n
>> â = "
>> < = <
>> > = >
>> ' = '
>> F = F
>> o = o
>> f = f
>> e = e
>> O = O
>>
>> This all works "as advertised" */except/* for the '\r' => '\\n'
>> replacement. Debugging the code, I see that my '\r' character is
>> "escaped" to '\\r' and the '\\n' to 'n' when they are read in from
>> the file.
>>
>> I've been googling hard and reading the Python docs, trying to get my
>> head around character encoding, but I just can't figure out how to get
>> these bits of code to do what I want.
>>
>> It seems to me that I need to either:
>>
>>* change the way I represent '\r' and '\\n' in my mapping file; or
>>* transform them somehow when I read them in
>>
>> However, I haven't figured out how to do either of these.
>>
>> TIA,
>>
>>
>
> I have had this problem too and can propose a solution ready to run out
> of my toolbox:
>
>
> class editor:
>
> def compile (self, replacements):
> targets, substitutes = zip (*replacements)
> re_targets = [re.escape (item) for item in targets]
> re_targets.sort (reverse = True)
> self.targets_set = set (targets)
> self.table = dict (replacements)
> regex_string = '|'.join (re_targets)
> self.regex = re.compile (regex_string, re.DOTALL)
>
> def edit (self, text, eat = False):
> hits = self.regex.findall (text)
> nohits = self.regex.split (text)
> valid_hits = set (hits) & self.targets_set # Ignore targets
> with illegal re modifiers.
Can you give an example of an ignored target? I don't see the light...
> if valid_hits:
> substitutes = [self.table [item] for item in hits if item
> in valid_hits] + [] # Make lengths equal for zip to work right
That looks wrong...
> if eat:
> output = ''.join (substitutes)
> else:
> zipped = zip (nohits, substitutes)
> output = ''.join (list (reduce (lambda a, b: a + b,
> [zipped][0]))) + nohits [-1]
> else:
> if eat:
> output = ''
> else:
> output = input
...and so does this.
> return output
>
> >>> substitutions = (
> ('\r', '\n'),
> ('<', '<'),
> ('>', '>'),
> ('o', 'o'),
> ('f', 'f'),
> ('e', 'e'),
> ('O', 'O'),
> )
>
> Order doesn't matter. Add new ones at the end.
>
> >>> e = editor ()
> >>> e.compile (substitutions)
>
> A simple way of testing is running the substitutions through the editor
>
> >>> print e.edit (repr (substitutions))
> (('\r', '\n'), ('<', '<'), ('>', '>'), ('o', 'o'), ('f', 'f'), ('e',
> 'e'), ('O', 'O'))
>
> The escapes need to be tested separately
>
> >>> print e.edit ('abc\rdef')
> abc
> def
>
> Note: This editor's compiler compiles the substitution list to a
Strange location for a comma
Hello,
At the end of the last line of the following program,
there is a comma, I dont understand why ?
Thx
from cx_Freeze import setup, Executable
# On appelle la fonction setup
setup(
name = "salut",
version = "0.1",
description = "Ce programme vous dit bonjour",
executables = [Executable("salut.py")],# <--- HERE
)
--
https://mail.python.org/mailman/listinfo/python-list
Re: Strange location for a comma
"ast" a écrit dans le message de news:[email protected]... Hello, At the end of the last line of the following program, there is a comma, I dont understand why ? Thx from cx_Freeze import setup, Executable # On appelle la fonction setup setup( name = "salut", version = "0.1", description = "Ce programme vous dit bonjour", executables = [Executable("salut.py")],# <--- HERE ) Ok its understood, it's a 1 element only tuple example: A = 5, A (5,) A = (6) A 6 -- https://mail.python.org/mailman/listinfo/python-list
sending push notifications
I'm looking for people's experiences with the different ways to send push notifications to mobile devices. I have an app that will be running on Amazon, so I can use their SNS API or I can do it myself. >From googling there appear to be a few different packages but PyAPNs and python-gcm seem to be the most popular. And for interfacing to SNS boto seems to be the choice. Anyone here used any of these or other packages? -- https://mail.python.org/mailman/listinfo/python-list
Re: Strange location for a comma
In a message of Thu, 03 Sep 2015 14:20:06 +0200, "ast" writes:
>Hello,
>
>At the end of the last line of the following program,
>there is a comma, I dont understand why ?
>
>Thx
>
>
>from cx_Freeze import setup, Executable
>
># On appelle la fonction setup
>setup(
>name = "salut",
>version = "0.1",
>description = "Ce programme vous dit bonjour",
>executables = [Executable("salut.py")],# <--- HERE
>)
In python a tuple consists of a number of values separated by commas.
see: https://docs.python.org/3/tutorial/datastructures.html#tuples-and-sequences
or https://docs.python.org/2/tutorial/datastructures.html#tuples-and-sequences
for Python 2.
The round parentheses aren't significant.
So:
>>> def Executable(arg):
... return arg
...
>>> executables = [Executable("salut.py")],
>>> executables
(['salut.py'],)
>>>
Laura
--
https://mail.python.org/mailman/listinfo/python-list
Re: Strange location for a comma
ast wrote: > > "ast" a écrit dans le message de > news:[email protected]... >> Hello, >> At the end of the last line of the following program, >> there is a comma, I dont understand why ? >> >> Thx >> >> >> from cx_Freeze import setup, Executable >> >> # On appelle la fonction setup >> setup( >>name = "salut", >>version = "0.1", >>description = "Ce programme vous dit bonjour", >>executables = [Executable("salut.py")],# <--- HERE >> ) >> >> > > Ok its understood, it's a 1 element only tuple > > example: > A = 5, A > (5,) > A = (6) A > 6 > No, in a function call an extra comma has no effect: >>> def f(x): return x ... >>> f(42) 42 >>> f(42,) 42 >>> f(x=42) 42 >>> f(x=42,) 42 The only reason I see to add an extra comma are smaller and easier to read diffs when you make a change: $ cat before.py func( arg_one=1, arg_two=2 ) func( arg_one=1, arg_two=2, ) $ cat after.py func( arg_one=1, arg_two=2, arg_three=3 ) func( arg_one=1, arg_two=2, arg_three=3, ) $ diff -u before.py after.py --- before.py 2015-09-03 14:44:27.709735075 +0200 +++ after.py2015-09-03 14:44:55.275958331 +0200 @@ -1,9 +1,11 @@ func( arg_one=1, -arg_two=2 +arg_two=2, +arg_three=3 ) func( arg_one=1, arg_two=2, +arg_three=3, ) -- https://mail.python.org/mailman/listinfo/python-list
Re: Strange location for a comma
On 2015-09-03 13:28, ast wrote: "ast" a écrit dans le message de news:[email protected]... Hello, At the end of the last line of the following program, there is a comma, I dont understand why ? Thx from cx_Freeze import setup, Executable # On appelle la fonction setup setup( name = "salut", version = "0.1", description = "Ce programme vous dit bonjour", executables = [Executable("salut.py")],# <--- HERE ) Ok its understood, it's a 1 element only tuple example: A = 5, A (5,) A = (6) A 6 No, it's not a tuple, because it's part of the argument list of 'setup'. A trailing comma is allowed in argument lists, tuples, lists, etc. >>> (1, 2, ) (1, 2) >>> [1, 2, ] [1, 2] >>> {1, 2, } {1, 2} >>> print(1, 2, ) 1 2 >>> {'1': 'one', '2': 'two', } {'2': 'two', '1': 'one'} It's nice to be able to do that because if you write the items on separate lines, like in your example, it's simpler when editing: all of the lines can end with a comma; if you add a new line, you don't also have to add a comma to the end of the previous line (a new line is added, and that's that); when removing a line, you don't also have to remove the comma from the end of the previous line (an old line is removed, and that's that). -- https://mail.python.org/mailman/listinfo/python-list
Fwd: Strange location for a comma
>>
>> # On appelle la fonction setup
>> setup(
>>name = "salut",
>>version = "0.1",
>>description = "Ce programme vous dit bonjour",
>>executables = [Executable("salut.py")],# <--- HERE
>> )
>>
>>
>
> Ok its understood, it's a 1 element only tuple
>
> example:
>
A = 5,
A
>
> (5,)
>
A = (6)
A
>
> 6
No. It's not a tuple in your case (calling 'setup' function)
a = 1,2, # <- extra comma
print a
b = 1, # <- extra comma
print b
=>
(1, 2) # ignored
(1,)# made tuple
and
def f(a, b):
print a,b
f(1,2,) # <- extra comma
=>
1 2 # ignored
Under some circumstances python ignores "excess" comma. At least
inside list definition [1,2,3,] and function calls f(1,2,)
Vladimir
http://itunes.apple.com/us/app/python-code-samples/id1025613117
--
https://mail.python.org/mailman/listinfo/python-list
Re: sending push notifications
In a message of Thu, 03 Sep 2015 08:30:35 -0400, Larry Martell writes: >I'm looking for people's experiences with the different ways to send >push notifications to mobile devices. I have an app that will be >running on Amazon, so I can use their SNS API or I can do it myself. >>From googling there appear to be a few different packages but PyAPNs >and python-gcm seem to be the most popular. And for interfacing to SNS >boto seems to be the choice. Anyone here used any of these or other >packages? You might want to try this question on the very quiet, but not dead yet https://mail.python.org/mailman/listinfo/mobile-sig/ Laura -- https://mail.python.org/mailman/listinfo/python-list
Re: Strange location for a comma
No, I am wrong. You are in the middle of a fuction definition. You are correct, that is a wierd place for a comma, though I can see doing that if you anticipate adding more arguments to the function in the near future. Laura -- https://mail.python.org/mailman/listinfo/python-list
Re: Strange location for a comma
"ast" a écrit dans le message de news:[email protected]... Hello, At the end of the last line of the following program, there is a comma, I dont understand why ? Thx from cx_Freeze import setup, Executable # On appelle la fonction setup setup( name = "salut", version = "0.1", description = "Ce programme vous dit bonjour", executables = [Executable("salut.py")],# <--- HERE ) understood Thx all -- https://mail.python.org/mailman/listinfo/python-list
Re: Python handles globals badly.
Reflecting the answers I want to add following first:
I should have better started a new thread.
But now it is here, I want just clarify something before
I move on (later) with repsonding.
I think this has lead to some confusing.
There are now two main topics in this thread.
First topic:
"sharing globals between modules"
Where globals is meant as vars used throughout the app.
This is the topic why Skybuck starts the thread.
And yes I agree globals can be bad design
and it is solved via outsourcing to an extra module and used via imports.
I misinterpreted this topic a little by thinking
the focus is more about the use of the badly "global" keyword
(in my point of view) and added therefore my post here as
Second topic:
"Forced to use "global" for write-access inside functions
is over-regulation and should be removed."
This topic has nothing todo with sharing globals.
It is about in the scope of a single module only.
When I have written globals in this topic
I have meant and mean vars defined in a module outside
functions and used inside function blocks.
Sorry if this has lead to confusion, but so long
I have read docs I would say that these vars are
often named as globals although I meant module vars.
Reason is that module scope is the highest
scope and often referred as the global scope.
That is also why I dislike the word "global" too.
I talk about this construct:
Sample "Bad":
module A
_x = 0
def y():
global x
_x=1
and I aim for - it would be nicer to allow for simplicity
writing this without the keyword "global"
and give this small responsibility ("write protection")
back to the developer:
Sample "Good":
module A
_x = 0
def y():
_x=1
why - this I have tried and try to explain in my and your posts
in the hope a PEP will arise which frees me and hopefully
a lot other developers getting forced to use "global"
(If developers need this "global" - ok, but I and
hopefully more want not to be forced with that
code-contaminator, especially having a lot more vars)
Said that, I will not respond to comments about sharing globals
--
https://mail.python.org/mailman/listinfo/python-list
Re: Reading \n unescaped from a file
On 09/03/2015 11:24 AM, Peter Otten wrote:
Friedrich Rentsch wrote:
On 09/02/2015 04:03 AM, Rob Hills wrote:
Hi,
I am developing code (Python 3.4) that transforms text data from one
format to another.
As part of the process, I had a set of hard-coded str.replace(...)
functions that I used to clean up the incoming text into the desired
output format, something like this:
dataIn = dataIn.replace('\r', '\\n') # Tidy up linefeeds
dataIn = dataIn.replace('<','<') # Tidy up < character
dataIn = dataIn.replace('>','>') # Tidy up < character
dataIn = dataIn.replace('o','o') # No idea why but lots of
these: convert to 'o' character dataIn =
dataIn.replace('f','f') # .. and these: convert to 'f'
character
dataIn = dataIn.replace('e','e') # .. 'e'
dataIn = dataIn.replace('O','O') # .. 'O'
These statements transform my data correctly, but the list of statements
grows as I test the data so I thought it made sense to store the
replacement mappings in a file, read them into a dict and loop through
that to do the cleaning up, like this:
with open(fileName, 'r+t', encoding='utf-8') as mapFile:
for line in mapFile:
line = line.strip()
try:
if (line) and not line.startswith('#'):
line = line.split('#')[:1][0].strip() # trim any
trailing comments name, value = line.split('=')
name = name.strip()
self.filterMap[name]=value.strip()
except:
self.logger.error('exception occurred parsing line
[{0}] in file [{1}]'.format(line, fileName)) raise
Elsewhere, I use the following code to do the actual cleaning up:
def filter(self, dataIn):
if dataIn:
for token, replacement in self.filterMap.items():
dataIn = dataIn.replace(token, replacement)
return dataIn
My mapping file contents look like this:
\r = \\n
â = "
< = <
> = >
' = '
F = F
o = o
f = f
e = e
O = O
This all works "as advertised" */except/* for the '\r' => '\\n'
replacement. Debugging the code, I see that my '\r' character is
"escaped" to '\\r' and the '\\n' to 'n' when they are read in from
the file.
I've been googling hard and reading the Python docs, trying to get my
head around character encoding, but I just can't figure out how to get
these bits of code to do what I want.
It seems to me that I need to either:
* change the way I represent '\r' and '\\n' in my mapping file; or
* transform them somehow when I read them in
However, I haven't figured out how to do either of these.
TIA,
I have had this problem too and can propose a solution ready to run out
of my toolbox:
class editor:
def compile (self, replacements):
targets, substitutes = zip (*replacements)
re_targets = [re.escape (item) for item in targets]
re_targets.sort (reverse = True)
self.targets_set = set (targets)
self.table = dict (replacements)
regex_string = '|'.join (re_targets)
self.regex = re.compile (regex_string, re.DOTALL)
def edit (self, text, eat = False):
hits = self.regex.findall (text)
nohits = self.regex.split (text)
valid_hits = set (hits) & self.targets_set # Ignore targets
with illegal re modifiers.
Can you give an example of an ignored target? I don't see the light...
if valid_hits:
substitutes = [self.table [item] for item in hits if item
in valid_hits] + [] # Make lengths equal for zip to work right
That looks wrong...
if eat:
output = ''.join (substitutes)
else:
zipped = zip (nohits, substitutes)
output = ''.join (list (reduce (lambda a, b: a + b,
[zipped][0]))) + nohits [-1]
else:
if eat:
output = ''
else:
output = input
...and so does this.
return output
>>> substitutions = (
('\r', '\n'),
('<', '<'),
('>', '>'),
('o', 'o'),
('f', 'f'),
('e', 'e'),
('O', 'O'),
)
Order doesn't matter. Add new ones at the end.
>>> e = editor ()
>>> e.compile (substitutions)
A simple way of testing is running the substitutions through the editor
>>> print e.edit (repr (substitutions))
(('\r', '\n'), ('<', '<'), ('>', '>'), ('o', 'o'), ('f', 'f'), ('e',
'e'), ('O', 'O'))
The escapes need to be tested separately
>>> print e.edit ('abc\rdef')
abc
def
Note: This editor's compiler compiles the substitution list to a regular
expression which the editor uses to find all matches in the text passed
to edit. There has got to be a limit to the size of a text which a
regular expression can handle. I don't know what this limit is. To be on
the safe side,
Re: Python handles globals badly.
On Thu, Sep 3, 2015 at 11:22 PM, wrote:
> Sample "Good":
> module A
>_x = 0
>
>def y():
> _x=1
>
>
> why - this I have tried and try to explain in my and your posts
> in the hope a PEP will arise which frees me and hopefully
> a lot other developers getting forced to use "global"
> (If developers need this "global" - ok, but I and
> hopefully more want not to be forced with that
> code-contaminator, especially having a lot more vars)
Okay. Let's suppose that some magic is worked out that makes this
work. Now let's try this example:
def x(q):
for word in generate_words():
if word.matches(q):
return word
def y():
word = x("blue")
otherword = x("green")
if word < otherword: return otherword
return x("red")
How would you reason about this code? Would you not expect that the
instances of 'word' in each function are completely independent? (And
while this is a contrived example, the exact same thing happens *a
lot*, where the name used in a "return" statement is the same as the
name that thing gets assigned to. After all, if it's a logical name
for that thing in one place, it's likely a logical name in the other,
too.) According to your proposal, they would cease to be independent
if the module grows an attribute 'word'. Since, in Python, such
attributes can be injected from outside, there is literally no way to
reason about this code in isolation. That makes it very difficult to
track down problems.
Definitely do not like this.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: Reading \n unescaped from a file
Friedrich Rentsch wrote: > On 09/03/2015 11:24 AM, Peter Otten wrote: >> Friedrich Rentsch wrote: > I appreciate your identifying two mistakes. I am curious to know what > they are. Sorry for not being explicit. >>> substitutes = [self.table [item] for item in hits if item >>> in valid_hits] + [] # Make lengths equal for zip to work right >> That looks wrong... You are adding an empty list here. I wondered what you were trying to achieve with that. >>> output = input >> ...and so does this. That seems to be the only occurence of the name "input" in your code. Did you mean "text" or do you really want to return the built-in? -- https://mail.python.org/mailman/listinfo/python-list
Porting Python Application to a new linux machine
Dear all, I have my python scripts that use several python libraries such as h5py, pyside, numpy In Windows I have an installer that will install python locally on user machine and so my program gets access to this local python and runs successfully. How can I do this in Linux ? ( I want to install python plus my program on the user machine.) I do not want to use the user´s python or to install python on the user´s machine on root. Thanks in Advance for your help, -- https://mail.python.org/mailman/listinfo/python-list
continue vs. pass in this IO reading and writing
Good Morning:
I am experimenting with many exception handling and utilizing continue vs pass.
After pouring over a lot of material on SO and other forums I am still unclear
as to the difference when setting variables and applying functions within
multiple "for" loops.
Specifically, I understand that the general format in the case of pass and
using else is the following:
try:
doSomething()
except Exception:
pass
else:
stuffDoneIf()
TryClauseSucceeds()
However, I am uncertain as to how this executes in a context like this:
import glob
import csv
from collections import OrderedDict
interesting_files = glob.glob("*.csv")
header_saved = False
with open('merged_output_mod.csv','w') as fout:
for filename in interesting_files:
print("execution here again")
with open(filename) as fin:
try:
header = next(fin)
print("Entering Try and Except")
except:
StopIteration
continue
else:
if not header_saved:
fout.write(header)
header_saved = True
print("We got here")
for line in fin:
fout.write(line)
My questions are (for some reason my interpreter does not print out any
readout):
1. after the exception is raised does the continue return back up to the
beginning of the for loop (and the "else" conditional is not even encountered)?
2. How would a pass behave in this situation?
Thanks for your feedback.
Sincerely,
Saran
--
https://mail.python.org/mailman/listinfo/python-list
Re: Strange location for a comma
On 2015-09-03 14:48, Peter Otten wrote: > The only reason I see to add an extra comma are smaller and easier > to read diffs when you make a change: While that's the primary reason I do it, it's also helpful if you have a bunch of named keyword arguments and want sort/rearrange them (usually for clarity/grouping). You don't have to worry about finding the previous-last-item and adding a comma to it and then finding the new-last-item and removing its comma. Also, when adding a new item, you can just copy an existing line, paste it, and modify the salient parts without needing to append a comma to one line or delete it from the pasted line. But the improvement in diff output? That's a big win for me. I notice it most when I *can't* use it, like in writing SQL: SELECT col1, col2, col3, -- grr, can't do this FROM tblExample so my SQL diffs are the "removed this line and replaced it with something almost identical except it now has a comma". Harumph. -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: Python handles globals badly.
Before responding (later) I have to add something additional first: About the OO comments (Note again for this 2nd main topic of this thread: the term "globals" - it is meant only as the vars of a module outside functions and not sharing vars throughout the app the term "global" - Python keyword for write access inside functions) Yes OO is a solution but Python invites also developers using functional or procedural style. I have used OO-terms to make it more visible to OO-developers or simply cause it is common knowlegde: I dont have and wanted not compare OO terminology with Python OO structure. When I have compared OO class members with Python globals or when I have used e.g. the term singleton than I have described the behaviour of a module from OO point of view and to show that OO languages need no"global"-keyword to fulfil its tasks, and to show that procedural style used in that manner is like nearby an OO-solution. So you dont need OO under all circumstances. There is a procedural/functional way too. Even other comparisons like type-safety is nothing else but to show that such languages need no "global" keyword. So, mainly with my comparison I tried to argue that there is no no need for a "global" keyword. Said that, I will not respond to comments about using OO or about comparisons made with other languages. (And by the way, OO in Python has something similiar (a.k.a "self"-keyword)) -- https://mail.python.org/mailman/listinfo/python-list
Re: continue vs. pass in this IO reading and writing
On Fri, Sep 4, 2015 at 1:05 AM, kbtyo wrote:
> However, I am uncertain as to how this executes in a context like this:
>
> import glob
> import csv
> from collections import OrderedDict
>
> interesting_files = glob.glob("*.csv")
>
> header_saved = False
> with open('merged_output_mod.csv','w') as fout:
>
> for filename in interesting_files:
> print("execution here again")
> with open(filename) as fin:
> try:
> header = next(fin)
> print("Entering Try and Except")
> except:
> StopIteration
> continue
I think what you want here is:
except StopIteration:
continue
The code you have will catch _any_ exception, and then look up the
name StopIteration (and discard it).
> else:
> if not header_saved:
> fout.write(header)
> header_saved = True
> print("We got here")
> for line in fin:
> fout.write(line)
>
> My questions are (for some reason my interpreter does not print out any
> readout):
>
> 1. after the exception is raised does the continue return back up to the
> beginning of the for loop (and the "else" conditional is not even
> encountered)?
>
> 2. How would a pass behave in this situation?
The continue statement means "skip the rest of this loop's body and go
to the next iteration of the loop, if there is one". In this case,
there's no further body, so it's going to be the same as "pass" (which
means "do nothing").
For the rest, I think your code should be broadly functional. Of
course, it assumes that your files all have compatible headers, but
presumably you know that that's safe.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: Porting Python Application to a new linux machine
On Thu, Sep 3, 2015 at 10:32 AM, Heli Nix wrote: > Dear all, > > I have my python scripts that use several python libraries such as h5py, > pyside, numpy > > In Windows I have an installer that will install python locally on user > machine and so my program gets access to this local python and runs > successfully. > > How can I do this in Linux ? ( I want to install python plus my program on > the user machine.) I do not want to use the user´s python or to install > python on the user´s machine on root. > > Thanks in Advance for your help, > > -- > https://mail.python.org/mailman/listinfo/python-list Look into virtualenv or virtualenvwrapper. It will let you load a local python engine along with local copies of the modules you need to run your application. Pip is the weapon of choice to load the libraries, or pip3 with python 3.x -- Joel Goldstick http://joelgoldstick.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Porting Python Application to a new linux machine
Il 03/09/2015 16:32, Heli Nix ha scritto: How can I do this in Linux ? As far as I know, in general a Linux distro comes with Python already installed. All you have to do is check if the installed version matches your needs. Tipically, you'll find Python 2.7; however, I know there are distros with Python3.x as default (Fedora?) -- Ciao! Luca -- https://mail.python.org/mailman/listinfo/python-list
Re: Porting Python Application to a new linux machine
On Fri, Sep 4, 2015 at 1:31 AM, Luca Menegotto wrote: > Il 03/09/2015 16:32, Heli Nix ha scritto: > >> How can I do this in Linux ? > > > As far as I know, in general a Linux distro comes with Python already > installed. > All you have to do is check if the installed version matches your needs. > Tipically, you'll find Python 2.7; however, I know there are distros with > Python3.x as default (Fedora?) Also Ubuntu. If you want to work across multiple Linux distros, the easiest way is to tell people to install either "python2" or "python3" using their system package manager, and then use that. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: continue vs. pass in this IO reading and writing
On Thursday, September 3, 2015 at 11:27:58 AM UTC-4, Chris Angelico wrote:
> On Fri, Sep 4, 2015 at 1:05 AM, kbtyo wrote:
> > However, I am uncertain as to how this executes in a context like this:
> >
> > import glob
> > import csv
> > from collections import OrderedDict
> >
> > interesting_files = glob.glob("*.csv")
> >
> > header_saved = False
> > with open('merged_output_mod.csv','w') as fout:
> >
> > for filename in interesting_files:
> > print("execution here again")
> > with open(filename) as fin:
> > try:
> > header = next(fin)
> > print("Entering Try and Except")
> > except:
> > StopIteration
> > continue
>
> I think what you want here is:
>
> except StopIteration:
> continue
>
> The code you have will catch _any_ exception, and then look up the
> name StopIteration (and discard it).
>
> > else:
> > if not header_saved:
> > fout.write(header)
> > header_saved = True
> > print("We got here")
> > for line in fin:
> > fout.write(line)
> >
> > My questions are (for some reason my interpreter does not print out any
> > readout):
> >
> > 1. after the exception is raised does the continue return back up to the
> > beginning of the for loop (and the "else" conditional is not even
> > encountered)?
> >
> > 2. How would a pass behave in this situation?
>
> The continue statement means "skip the rest of this loop's body and go
> to the next iteration of the loop, if there is one". In this case,
> there's no further body, so it's going to be the same as "pass" (which
> means "do nothing").
>
> For the rest, I think your code should be broadly functional. Of
> course, it assumes that your files all have compatible headers, but
> presumably you know that that's safe.
>
> ChrisA
Hi ChrisA:
Thank you for the elaboration. So, what I hear you saying is that (citing, "In
this case, there's no further body, so it's going to be the same as "pass"
(which
means "do nothing")") that the else block is not entered. For exma
Do you mind elaborating on what you meant by "compatible headers?". The files
that I am processing may or may not have the same headers (but if they do they
should add the respective values only).
--
https://mail.python.org/mailman/listinfo/python-list
Re: continue vs. pass in this IO reading and writing
On Thursday, September 3, 2015 at 11:27:58 AM UTC-4, Chris Angelico wrote:
> On Fri, Sep 4, 2015 at 1:05 AM, kbtyo wrote:
> > However, I am uncertain as to how this executes in a context like this:
> >
> > import glob
> > import csv
> > from collections import OrderedDict
> >
> > interesting_files = glob.glob("*.csv")
> >
> > header_saved = False
> > with open('merged_output_mod.csv','w') as fout:
> >
> > for filename in interesting_files:
> > print("execution here again")
> > with open(filename) as fin:
> > try:
> > header = next(fin)
> > print("Entering Try and Except")
> > except:
> > StopIteration
> > continue
>
> I think what you want here is:
>
> except StopIteration:
> continue
>
> The code you have will catch _any_ exception, and then look up the
> name StopIteration (and discard it).
>
> > else:
> > if not header_saved:
> > fout.write(header)
> > header_saved = True
> > print("We got here")
> > for line in fin:
> > fout.write(line)
> >
> > My questions are (for some reason my interpreter does not print out any
> > readout):
> >
> > 1. after the exception is raised does the continue return back up to the
> > beginning of the for loop (and the "else" conditional is not even
> > encountered)?
> >
> > 2. How would a pass behave in this situation?
>
> The continue statement means "skip the rest of this loop's body and go
> to the next iteration of the loop, if there is one". In this case,
> there's no further body, so it's going to be the same as "pass" (which
> means "do nothing").
So what I hear you saying is I am not entering the else" block? Hence, when
each file is read, the rest of the suite is not applied - specifically,
if not header_saved:
fout.write(header)
header_saved = True
print("We got here")
>
> For the rest, I think your code should be broadly functional. Of
> course, it assumes that your files all have compatible headers, but
> presumably you know that that's safe.
>
> ChrisA
Would you mind elaborating on what you meant by "compatible headers"? I have
files that may have different headers. If they are different, they should be
appended (along with their values). If there are duplicate headers, then their
values should just be added.
--
https://mail.python.org/mailman/listinfo/python-list
Re: continue vs. pass in this IO reading and writing
On Fri, Sep 4, 2015 at 1:38 AM, kbtyo wrote: > Thank you for the elaboration. So, what I hear you saying is that (citing, > "In this case, there's no further body, so it's going to be the same as > "pass" (which > means "do nothing")") that the else block is not entered. For exma Seems like a cut-off paragraph here, but yes. In a try/except/else block, the 'else' block executes only if the 'try' didn't raise an exception of the specified type(s). > Do you mind elaborating on what you meant by "compatible headers?". The files > that I am processing may or may not have the same headers (but if they do > they should add the respective values only). > Your algorithm is basically: Take the entire first file, including its header, and then append all other files after skipping their first lines. If you want a smarter form of CSV merge, I would recommend using the 'csv' module, and probably doing a quick check of all files before you begin, so as to collect up the full set of headers. That'll also save you the hassle of playing around with StopIteration as you read in the headers. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Python handles globals badly.
On 09/03/2015 07:22 AM, [email protected] wrote: > First topic: > "sharing globals between modules" > Where globals is meant as vars used throughout the app. > > This is the topic why Skybuck starts the thread. The answer to this is simple and elegant. Use a third module to store globals. Each module that needs it can simply import it. -- https://mail.python.org/mailman/listinfo/python-list
Re: sending push notifications
On Thu, Sep 3, 2015 at 8:54 AM, Laura Creighton wrote: > In a message of Thu, 03 Sep 2015 08:30:35 -0400, Larry Martell writes: >>I'm looking for people's experiences with the different ways to send >>push notifications to mobile devices. I have an app that will be >>running on Amazon, so I can use their SNS API or I can do it myself. >>>From googling there appear to be a few different packages but PyAPNs >>and python-gcm seem to be the most popular. And for interfacing to SNS >>boto seems to be the choice. Anyone here used any of these or other >>packages? > > You might want to try this question on the very quiet, but not dead > yet https://mail.python.org/mailman/listinfo/mobile-sig/ Will do. Thanks. -- https://mail.python.org/mailman/listinfo/python-list
Re: Strange location for a comma
Tim, Doesn't work for the first column in SQL, but we tend to put the comma and a space before the column name. It makes it easier to move things around and (debateably) more readable. It is also very obvious when you have missed a comma this way. - Nick On Thu, 3 Sep 2015 16:14 Tim Chase wrote: > On 2015-09-03 14:48, Peter Otten wrote: > > The only reason I see to add an extra comma are smaller and easier > > to read diffs when you make a change: > > While that's the primary reason I do it, it's also helpful if you > have a bunch of named keyword arguments and want sort/rearrange them > (usually for clarity/grouping). You don't have to worry about finding > the previous-last-item and adding a comma to it and then finding the > new-last-item and removing its comma. Also, when adding a new > item, you can just copy an existing line, paste it, and modify the > salient parts without needing to append a comma to one line or > delete it from the pasted line. > > But the improvement in diff output? That's a big win for me. > > I notice it most when I *can't* use it, like in writing SQL: > > SELECT > col1, > col2, > col3, -- grr, can't do this > FROM tblExample > > so my SQL diffs are the "removed this line and replaced it with > something almost identical except it now has a comma". Harumph. > > -tkc > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- - Nick -- https://mail.python.org/mailman/listinfo/python-list
Re: Porting Python Application to a new linux machine
On Fri, Sep 4, 2015 at 1:53 AM, Nick Sarbicki wrote: > Is 3.x the default on ubuntu now? My 14.10 is still 2.7. Although it does > have python3 installed. I'm not sure. I think I read somewhere that the newest Ubuntus would ship with python3 preinstalled, but python2 not (though of course it'd be just an apt-get away). Maybe I'm wrong, and that's still in the future, but certainly it's the intention. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Porting Python Application to a new linux machine
Is 3.x the default on ubuntu now? My 14.10 is still 2.7. Although it does have python3 installed. On Thu, 3 Sep 2015 16:40 Chris Angelico wrote: > On Fri, Sep 4, 2015 at 1:31 AM, Luca Menegotto > wrote: > > Il 03/09/2015 16:32, Heli Nix ha scritto: > > > >> How can I do this in Linux ? > > > > > > As far as I know, in general a Linux distro comes with Python already > > installed. > > All you have to do is check if the installed version matches your needs. > > Tipically, you'll find Python 2.7; however, I know there are distros with > > Python3.x as default (Fedora?) > > Also Ubuntu. If you want to work across multiple Linux distros, the > easiest way is to tell people to install either "python2" or "python3" > using their system package manager, and then use that. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -- - Nick -- https://mail.python.org/mailman/listinfo/python-list
Re: continue vs. pass in this IO reading and writing
On Thursday, September 3, 2015 at 11:52:16 AM UTC-4, Chris Angelico wrote:
> On Fri, Sep 4, 2015 at 1:38 AM, kbtyo wrote:
> > Thank you for the elaboration. So, what I hear you saying is that (citing,
> > "In this case, there's no further body, so it's going to be the same as
> > "pass" (which
> > means "do nothing")") that the else block is not entered. For exma
>
> Seems like a cut-off paragraph here, but yes. In a try/except/else
> block, the 'else' block executes only if the 'try' didn't raise an
> exception of the specified type(s).
>
> > Do you mind elaborating on what you meant by "compatible headers?". The
> > files that I am processing may or may not have the same headers (but if
> > they do they should add the respective values only).
> >
>
> Your algorithm is basically: Take the entire first file, including its
> header, and then append all other files after skipping their first
> lines. If you want a smarter form of CSV merge, I would recommend
> using the 'csv' module, and probably doing a quick check of all files
> before you begin, so as to collect up the full set of headers. That'll
> also save you the hassle of playing around with StopIteration as you
> read in the headers.
>
> ChrisA
I have files that may have different headers. If they are different, they
should be appended (along with their values). If there are duplicate headers,
then their values should just be added.
I have used CSV and collections. For some reason when I apply this algorithm,
all of my files are not added (the output is ridiculously small considering how
much goes in - think KB output vs MB input):
from glob import iglob
import csv
from collections import OrderedDict
files = sorted(iglob('*.csv'))
header = OrderedDict()
data = []
for filename in files:
with open(filename, 'r') as fin:
csvin = csv.DictReader(fin)
header.update(OrderedDict.fromkeys(csvin.fieldnames))
data.append(next(csvin))
with open('output_filename_version2.csv', 'w') as fout:
csvout = csv.DictWriter(fout, fieldnames=list(header))
csvout.writeheader()
csvout.writerows(data)
--
https://mail.python.org/mailman/listinfo/python-list
Re: continue vs. pass in this IO reading and writing
On 9/3/2015 11:05 AM, kbtyo wrote:
I am experimenting with many exception handling and utilizing continue vs pass.
'pass' is a do-nothing place holder. 'continue' and 'break' are jump
statements
[snip]
However, I am uncertain as to how this executes in a context like this:
import glob
import csv
from collections import OrderedDict
interesting_files = glob.glob("*.csv")
header_saved = False
with open('merged_output_mod.csv','w') as fout:
for filename in interesting_files:
print("execution here again")
with open(filename) as fin:
try:
header = next(fin)
print("Entering Try and Except")
except:
StopIteration
continue
else:
if not header_saved:
fout.write(header)
header_saved = True
print("We got here")
for line in fin:
fout.write(line)
My questions are (for some reason my interpreter does not print out any
readout):
1. after the exception is raised does the continue return back up to the beginning of the
for loop (and the "else" conditional is not even encountered)?
2. How would a pass behave in this situation?
Try it for yourself. Copy the following into a python shell or editor
(and run) see what you get.
for i in [-1, 0, 1]:
try:
j = 2//i
except ZeroDivisionError:
print('infinity')
continue
else:
print(j)
Change 'continue' to 'pass' and run again.
--
Terry Jan Reedy
--
https://mail.python.org/mailman/listinfo/python-list
Re: continue vs. pass in this IO reading and writing
On Fri, Sep 4, 2015 at 1:57 AM, kbtyo wrote:
> I have used CSV and collections. For some reason when I apply this algorithm,
> all of my files are not added (the output is ridiculously small considering
> how much goes in - think KB output vs MB input):
>
> from glob import iglob
> import csv
> from collections import OrderedDict
>
> files = sorted(iglob('*.csv'))
> header = OrderedDict()
> data = []
>
> for filename in files:
> with open(filename, 'r') as fin:
> csvin = csv.DictReader(fin)
> header.update(OrderedDict.fromkeys(csvin.fieldnames))
> data.append(next(csvin))
>
> with open('output_filename_version2.csv', 'w') as fout:
> csvout = csv.DictWriter(fout, fieldnames=list(header))
> csvout.writeheader()
> csvout.writerows(data)
You're collecting up just one row from each file. Since you say your
input is measured in MB (not GB or anything bigger), the simplest
approach is probably fine: instead of "data.append(next(csvin))", just
use "data.extend(csvin)", which should grab them all. That'll store
all your input data in memory, which should be fine if it's only a few
meg, and probably not a problem for anything under a few hundred meg.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: Reading \n unescaped from a file
Hi Friedrich,
On 03/09/15 16:40, Friedrich Rentsch wrote:
>
> On 09/02/2015 04:03 AM, Rob Hills wrote:
>> Hi,
>>
>> I am developing code (Python 3.4) that transforms text data from one
>> format to another.
>>
>> As part of the process, I had a set of hard-coded str.replace(...)
>> functions that I used to clean up the incoming text into the desired
>> output format, something like this:
>>
>> dataIn = dataIn.replace('\r', '\\n') # Tidy up linefeeds
>> dataIn = dataIn.replace('<','<') # Tidy up < character
>> dataIn = dataIn.replace('>','>') # Tidy up < character
>> dataIn = dataIn.replace('o','o') # No idea why but lots of
>> these: convert to 'o' character
>> dataIn = dataIn.replace('f','f') # .. and these: convert to
>> 'f' character
>> dataIn = dataIn.replace('e','e') # .. 'e'
>> dataIn = dataIn.replace('O','O') # .. 'O'
>>
>> These statements transform my data correctly, but the list of statements
>> grows as I test the data so I thought it made sense to store the
>> replacement mappings in a file, read them into a dict and loop through
>> that to do the cleaning up, like this:
>>
>> with open(fileName, 'r+t', encoding='utf-8') as mapFile:
>> for line in mapFile:
>> line = line.strip()
>> try:
>> if (line) and not line.startswith('#'):
>> line = line.split('#')[:1][0].strip() # trim
>> any trailing comments
>> name, value = line.split('=')
>> name = name.strip()
>> self.filterMap[name]=value.strip()
>> except:
>> self.logger.error('exception occurred parsing
>> line [{0}] in file [{1}]'.format(line, fileName))
>> raise
>>
>> Elsewhere, I use the following code to do the actual cleaning up:
>>
>> def filter(self, dataIn):
>> if dataIn:
>> for token, replacement in self.filterMap.items():
>> dataIn = dataIn.replace(token, replacement)
>> return dataIn
>>
>>
>> My mapping file contents look like this:
>>
>> \r = \\n
>> â = "
>> < = <
>> > = >
>> ' = '
>> F = F
>> o = o
>> f = f
>> e = e
>> O = O
>>
>> This all works "as advertised" */except/* for the '\r' => '\\n'
>> replacement. Debugging the code, I see that my '\r' character is
>> "escaped" to '\\r' and the '\\n' to 'n' when they are read in from
>> the file.
>>
>> I've been googling hard and reading the Python docs, trying to get my
>> head around character encoding, but I just can't figure out how to get
>> these bits of code to do what I want.
>>
>> It seems to me that I need to either:
>>
>>* change the way I represent '\r' and '\\n' in my mapping file; or
>>* transform them somehow when I read them in
>>
>> However, I haven't figured out how to do either of these.
>>
>> TIA,
>>
>>
>
> I have had this problem too and can propose a solution ready to run
> out of my toolbox:
>
>
> class editor:
>
> def compile (self, replacements):
> targets, substitutes = zip (*replacements)
> re_targets = [re.escape (item) for item in targets]
> re_targets.sort (reverse = True)
> self.targets_set = set (targets)
> self.table = dict (replacements)
> regex_string = '|'.join (re_targets)
> self.regex = re.compile (regex_string, re.DOTALL)
>
> def edit (self, text, eat = False):
> hits = self.regex.findall (text)
> nohits = self.regex.split (text)
> valid_hits = set (hits) & self.targets_set # Ignore targets
> with illegal re modifiers.
> if valid_hits:
> substitutes = [self.table [item] for item in hits if item
> in valid_hits] + [] # Make lengths equal for zip to work right
> if eat:
> output = ''.join (substitutes)
> else:
> zipped = zip (nohits, substitutes)
> output = ''.join (list (reduce (lambda a, b: a + b,
> [zipped][0]))) + nohits [-1]
> else:
> if eat:
> output = ''
> else:
> output = input
> return output
>
> >>> substitutions = (
> ('\r', '\n'),
> ('<', '<'),
> ('>', '>'),
> ('o', 'o'),
> ('f', 'f'),
> ('e', 'e'),
> ('O', 'O'),
> )
>
> Order doesn't matter. Add new ones at the end.
>
> >>> e = editor ()
> >>> e.compile (substitutions)
>
> A simple way of testing is running the substitutions through the editor
>
> >>> print e.edit (repr (substitutions))
> (('\r', '\n'), ('<', '<'), ('>', '>'), ('o', 'o'), ('f', 'f'), ('e',
> 'e'), ('O', 'O'))
>
> The escapes need to be tested separately
>
> >>> print e.edit ('abc\rdef')
> abc
> def
>
> Note: This editor's compiler compiles the substitution list to a
> regular expression which the editor uses to find all matches in the
> text passed to edit. There has got to be a limit to the size of a text
>
Re: Python handles globals badly.
On Thu, Sep 3, 2015 at 7:22 AM, wrote: > I think this has lead to some confusing. I don't think so. > First topic: > "sharing globals between modules" > Where globals is meant as vars used throughout the app. > > This is the topic why Skybuck starts the thread. > And yes I agree globals can be bad design > and it is solved via outsourcing to an extra module and used via imports. > > I misinterpreted this topic a little by thinking > the focus is more about the use of the badly "global" keyword > (in my point of view) and added therefore my post here as The only person whom I see talking about this in this thread is you disclaiming that you're not talking about it. (And I guess Skybuck is talking about it, but I don't see those.) > Said that, I will not respond to comments about sharing globals > Said that, I will not respond to comments about using OO or about comparisons made with other languages. I don't know what comments about using OO you're referring to either. I only see one suggestion to use classes, and you've already responded to that. As far as comparisons to other languages, you're the one who brought up the comparison to Java in the first place. You seem to be spending a lot of time talking about what you won't talk about, and very little time talking about your proposal, such as by what magic you expect the compiler to distinguish globals from locals without declarations. -- https://mail.python.org/mailman/listinfo/python-list
How do I real a SSL certs serial number using Python?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA512 I'm writing a simple tool that needs to read the serial number of a remote SSL certificate. I've poked around Google for a bit but can't find anything that fits the bill. Is this possible in Python? If so, would someone point me in the general direction of how to do it? Thanks, Anthony Papillion - -- Phone:1-(845) 666-1114 VoIP: [email protected] Skype:CajunTechie -BEGIN PGP SIGNATURE- Version: APG v1.1.1 iQJJBAEBCgAzBQJV6FtfLBxBbnRob255IFBhcGlsbGlvbiA8YW50aG9ueUBjYWp1 bnRlY2hpZS5vcmc+AAoJEEKq2nfie1EM5EIP/jUdLg03pPWksQcXOqiMtYAW65E8 43J5yYgJmjTM7a87s0CyYhKxJN9VO/trBptCPvowrwZ9AdDbPxQUzRvSni4Trzfh TTZi0K9rpoKqUcwX+z2EwRWDlyiDKWpq7DzdisLmqACL02pz/xQcBM/LPj9TvhKB NYhIY0jw4S0oISMWz/eqVyCd1RMHvxsDOM3wKVbwXKN2r5Bx+AC2F2S0qOneUcNX f9GNhbjDKleQPifrBQ2q3k6hnUaUbATELUHqsa3/p3/UIVv8OZ7ONKe17Ofh8Cxf 0mtmMuH7a5gAeCwwPQnU/nI6g9QXEDv/yRdqWX3bi11xw88jmMEBq2ybQyvAiAmm 2Czphjk87tkbdrYu6QKxLFLmaeAh8scl2XOlk+X8+hVasiG/px0nvvgPSy1s/nC8 pEMIiyUoFliq6IszuMshzHU6JCmvBKP0AmoVIodnJal1rR7vh2aoh9tKU92nrHGV e33tdP8JobfmFHQesHVUZVBvdsxO0othuQKKADMdmm31BfrSEydNdcA+9aTXwbUT ef8sz5eu7MzUu4aq63k/qwyaflP/TBNhTk6ByePvI/g4l1gDxGHskAt8tPBO2gT1 rTKYLOk2ckFh4TutD0IvdL3EyyxzrhlSfprjUJV8X3RWcyYDooPQN+STG4sBJUC2 vAc5oUGXdaHIWsbd =oAPu -END PGP SIGNATURE- -- https://mail.python.org/mailman/listinfo/python-list
Re: Reading \n unescaped from a file
Hi Chris,
On 03/09/15 06:10, Chris Angelico wrote:
> On Wed, Sep 2, 2015 at 12:03 PM, Rob Hills
> wrote:
>> My mapping file contents look like this:
>>
>> \r = \\n
>> “ = "
> Oh, lovely. Code page 1252 when you're expecting UTF-8. Sadly, you're
> likely to have to cope with a whole pile of other mojibake if that
> happens :(
Yeah, tell me about it!!!
> Technically, what's happening is that your "\r" is literally a
> backslash followed by the letter r; the transformation of backslash
> sequences into single characters is part of Python source code
> parsing. (Incidentally, why do you want to change a carriage return
> into backslash-n? Seems odd.)
>
> Probably the easiest solution would be a simple and naive replace(),
> looking for some very specific strings and ignoring everything else.
> Easy to do, but potentially confusing down the track if someone tries
> something fancy :)
>
> line = line.split('#')[:1][0].strip() # trim any trailing comments
> line = line.replace(r"\r", "\r") # repeat this for as many backslash
> escapes as you want to handle
>
> Be aware that this, while simple, is NOT capable of handling escaped
> backslashes. In Python, "\\r" comes out the same as r"\r", but with
> this parser, it would come out the same as "\\\r". But it might be
> sufficient for you.
Thanks for the explanation which has helped me understand the problem.
I also tried your approach but wound up with output data that somehow
had every single character escaped :-(
I've since decided I was being too obsessive trying to load *everything*
from my mapping file and have simply hard-coded my two escaped character
replacements for now and moved on to more important problems (ie the
Windoze Character soup that comprises my data and which I have to clean
up!).
Thanks again,
--
Rob Hills
Waikiki, Western Australia
--
https://mail.python.org/mailman/listinfo/python-list
Re: Strange location for a comma
In this case those are not tuples but rather arguments in a function call. The extra comma does not change the evaluation, my guess is that it is there for easier adding/removing arguments without having to care about trailing commas. Martin On 03/09/15 14:28, ast wrote: > > "ast" a écrit dans le message de > news:[email protected]... >> Hello, >> At the end of the last line of the following program, >> there is a comma, I dont understand why ? >> >> Thx >> >> >> from cx_Freeze import setup, Executable >> >> # On appelle la fonction setup >> setup( >>name = "salut", >>version = "0.1", >>description = "Ce programme vous dit bonjour", >>executables = [Executable("salut.py")],# <--- HERE >> ) >> >> > > Ok its understood, it's a 1 element only tuple > > example: > A = 5, A > (5,) > A = (6) A > 6 > -- https://mail.python.org/mailman/listinfo/python-list
Re: Porting Python Application to a new linux machine
Il 03/09/2015 17:53, Nick Sarbicki ha scritto: Is 3.x the default on ubuntu now? My 14.10 is still 2.7. Although it does have python3 installed. I've checked my Ubuntu 15.04, and the default is 2.7.9. There is also Python3 (3.4.3), but sorry, I can't remember if I've manually installed it or not. -- Ciao! Luca -- https://mail.python.org/mailman/listinfo/python-list
Re: Porting Python Application to a new linux machine
On Thu, Sep 3, 2015 at 10:39 AM, Chris Angelico wrote: > On Fri, Sep 4, 2015 at 1:31 AM, Luca Menegotto > wrote: > > Il 03/09/2015 16:32, Heli Nix ha scritto: > > > >> How can I do this in Linux ? > > > > > > As far as I know, in general a Linux distro comes with Python already > > installed. > > All you have to do is check if the installed version matches your needs. > > Tipically, you'll find Python 2.7; however, I know there are distros with > > Python3.x as default (Fedora?) > > Also Ubuntu. If you want to work across multiple Linux distros, the > easiest way is to tell people to install either "python2" or "python3" > using their system package manager, and then use that. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > You could also look into a more robust solution like placing your application environment into something like a Docker container. This would require your customer machine to be running Docker, but it makes deployments highly portable as the container will sit on top of just about any Linux flavor and can be entirely self contained. Brett -- https://mail.python.org/mailman/listinfo/python-list
Re: Reading \n unescaped from a file
Hi,
On 03/09/15 06:31, MRAB wrote:
> On 2015-09-02 03:03, Rob Hills wrote:
>> I am developing code (Python 3.4) that transforms text data from one
>> format to another.
>>
>> As part of the process, I had a set of hard-coded str.replace(...)
>> functions that I used to clean up the incoming text into the desired
>> output format, something like this:
>>
>> dataIn = dataIn.replace('\r', '\\n') # Tidy up linefeeds
>> dataIn = dataIn.replace('<','<') # Tidy up < character
>> dataIn = dataIn.replace('>','>') # Tidy up < character
>> dataIn = dataIn.replace('o','o') # No idea why but lots of
>> these: convert to 'o' character
>> dataIn = dataIn.replace('f','f') # .. and these: convert to
>> 'f' character
>> dataIn = dataIn.replace('e','e') # .. 'e'
>> dataIn = dataIn.replace('O','O') # .. 'O'
>>
> The problem with this approach is that the order of the replacements
> matters. For example, changing '<' to '<' and then '&' to '&'
> can give a different result to changing '&' to '&' and then '<'
> to '<'. If you started with the string '<', then the first order
> would go '<' => '<' => '<', whereas the second order
> would go '<' => '<' => '<'.
Ah yes, thanks for reminding me about that. I've since modified my code
to use a collections.OrderedDict to store my mappings.
...
>> This all works "as advertised" */except/* for the '\r' => '\\n'
>> replacement. Debugging the code, I see that my '\r' character is
>> "escaped" to '\\r' and the '\\n' to 'n' when they are read in from
>> the file.
>>
>> I've been googling hard and reading the Python docs, trying to get my
>> head around character encoding, but I just can't figure out how to get
>> these bits of code to do what I want.
>>
>> It seems to me that I need to either:
>>
>> * change the way I represent '\r' and '\\n' in my mapping file; or
>> * transform them somehow when I read them in
>>
>> However, I haven't figured out how to do either of these.
>>
> Try ast.literal_eval, although you'd need to make it look like a string
> literal first:
Thanks for the suggestion. For now, I've decided I was being too
pedantic trying to load my two escaped strings from a file and I've
simply hard coded them and moved on to other issues. I'll try this idea
later on though.
Cheers,
--
Rob Hills
Waikiki, Western Australia
--
https://mail.python.org/mailman/listinfo/python-list
Re: continue vs. pass in this IO reading and writing
On Thursday, September 3, 2015 at 12:12:04 PM UTC-4, Chris Angelico wrote:
> On Fri, Sep 4, 2015 at 1:57 AM, kbtyo wrote:
> > I have used CSV and collections. For some reason when I apply this
> > algorithm, all of my files are not added (the output is ridiculously small
> > considering how much goes in - think KB output vs MB input):
> >
> > from glob import iglob
> > import csv
> > from collections import OrderedDict
> >
> > files = sorted(iglob('*.csv'))
> > header = OrderedDict()
> > data = []
> >
> > for filename in files:
> > with open(filename, 'r') as fin:
> > csvin = csv.DictReader(fin)
> > header.update(OrderedDict.fromkeys(csvin.fieldnames))
> > data.append(next(csvin))
> >
> > with open('output_filename_version2.csv', 'w') as fout:
> > csvout = csv.DictWriter(fout, fieldnames=list(header))
> > csvout.writeheader()
> > csvout.writerows(data)
>
> You're collecting up just one row from each file. Since you say your
> input is measured in MB (not GB or anything bigger), the simplest
> approach is probably fine: instead of "data.append(next(csvin))", just
> use "data.extend(csvin)", which should grab them all. That'll store
> all your input data in memory, which should be fine if it's only a few
> meg, and probably not a problem for anything under a few hundred meg.
>
> ChrisA
H - good point. However, I may have to deal with larger files, but thank
you for the tip.
I am also wondering, based on what you stated, you are only "collecting up just
one row from each file"
I am fulfilling this, correct?
"I have files that may have different headers. If they are different, they
should be appended (along with their values) into the output. If there are
duplicate headers, then their values should just be added sequentially."
I am wondering how DictReader can skip empty rows by default and that this may
be happening that also extrapolates to the other rows.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python handles globals badly.
On 09/03/2015 10:15 AM, Ian Kelly wrote: > The only person whom I see talking about this in this thread is you > disclaiming that you're not talking about it. (And I guess Skybuck is > talking about it, but I don't see those.) I have a vague memory of Skybuck talking about globals over a year ago. That must be what tdev's responding to. Sadly Skybuck probably ditched Python a long time ago as he was spending his time trying to make it into Java rather than taking advantage of idiomatic Python programming. Those that try to program Java style in Python are going to be frustrated. -- https://mail.python.org/mailman/listinfo/python-list
Re: continue vs. pass in this IO reading and writing
Il 03/09/2015 17:05, kbtyo ha scritto: I am experimenting with many exception handling and utilizing > continue vs pass. After pouring over a lot of material on SO > and other forums I am still unclear as to the difference when > setting variables and applying functions within multiple "for" > loops. 'pass' and 'continue' have two very different meanings. 'pass' means 'don't do anything'; it's useful when you _have_ to put a statement but you _don't_need_ to put a statement. You can use it everywhere you want, with no other damage then adding a little weight to your code. A stupid example: if i == 0: pass else: do_something() 'continue', to be used in a loop (for or while) means 'ignore the rest of the code and go immediatly to the next iteration'. The statement refers to the nearest loop; so, if you have two nested loops, it refers to the inner one; another stupid example: for i in range(10): for j in range(10): if j < 5: continue do_something(i, j) # called only if j >= 5 -- Ciao! Luca -- https://mail.python.org/mailman/listinfo/python-list
Re: Porting Python Application to a new linux machine
On Fri, Sep 4, 2015 at 2:23 AM, Luca Menegotto wrote: > Il 03/09/2015 17:53, Nick Sarbicki ha scritto: >> >> Is 3.x the default on ubuntu now? My 14.10 is still 2.7. Although it >> does have python3 installed. > > > I've checked my Ubuntu 15.04, and the default is 2.7.9. > There is also Python3 (3.4.3), but sorry, I can't remember if I've manually > installed it or not. If you mean that typing "python" runs 2.7, then that's PEP 394 at work. For compatibility reasons, 'python' doesn't ever run Python 3. (At least, not any time soon.) The question is more: What comes installed on a fresh system? Anything can be dragged in as a dependency of some other package, but a normal Ubuntu desktop installation won't depend on Python 2 for anything. Or at least, that's the plan; I don't know whether it's been accomplished yet or not. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
XML Binding
Hi All, Is there any module available in python standard library for XML binding? If not, any other suggestions. Which is good for parsing large file? 1. XML binding 2. Creating our own classes Thanks, Palpandi -- https://mail.python.org/mailman/listinfo/python-list
Re: Porting Python Application to a new linux machine
Il 03/09/2015 18:49, Chris Angelico ha scritto: If you mean that typing "python" runs 2.7, then that's PEP 394 at work. For compatibility reasons, 'python' doesn't ever run Python 3. Please forgive me, Il make it clearer. I'm pretty shure that Ubuntu 15.04 comes with Python 2.7. I don't remember if Python 3 was preinstalled or if I had to install it manually. -- Ciao! Luca -- https://mail.python.org/mailman/listinfo/python-list
Re: Porting Python Application to a new linux machine
On Fri, Sep 4, 2015 at 3:29 AM, Luca Menegotto wrote: > Il 03/09/2015 18:49, Chris Angelico ha scritto: > >> If you mean that typing "python" runs 2.7, then that's PEP 394 at >> work. For compatibility reasons, 'python' doesn't ever run Python 3. > > > Please forgive me, Il make it clearer. > I'm pretty shure that Ubuntu 15.04 comes with Python 2.7. > I don't remember if Python 3 was preinstalled or if I had to install it > manually. Okay. I don't run any current Ubuntu anywhere, so I don't know. And I can't even find back the page now where the plans were being discussed; best I can find is this, about a year out of date now: https://wiki.ubuntu.com/Python/3 ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Porting Python Application to a new linux machine
I run ubuntu everywhere at home and python3 has come preinstalled since at least ubuntu 12.10. This article kind of covers it: https://wiki.ubuntu.com/Python Looks like they're suggesting that it's not been fully transitioned although definitely moving that way. On Thu, 3 Sep 2015 18:34 Chris Angelico wrote: > On Fri, Sep 4, 2015 at 3:29 AM, Luca Menegotto > wrote: > > Il 03/09/2015 18:49, Chris Angelico ha scritto: > > > >> If you mean that typing "python" runs 2.7, then that's PEP 394 at > >> work. For compatibility reasons, 'python' doesn't ever run Python 3. > > > > > > Please forgive me, Il make it clearer. > > I'm pretty shure that Ubuntu 15.04 comes with Python 2.7. > > I don't remember if Python 3 was preinstalled or if I had to install it > > manually. > > Okay. I don't run any current Ubuntu anywhere, so I don't know. And I > can't even find back the page now where the plans were being > discussed; best I can find is this, about a year out of date now: > > https://wiki.ubuntu.com/Python/3 > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -- - Nick -- https://mail.python.org/mailman/listinfo/python-list
Re: Python handles globals badly.
On 2015-09-03 17:43, Michael Torrie wrote: On 09/03/2015 10:15 AM, Ian Kelly wrote: The only person whom I see talking about this in this thread is you disclaiming that you're not talking about it. (And I guess Skybuck is talking about it, but I don't see those.) I have a vague memory of Skybuck talking about globals over a year ago. That must be what tdev's responding to. It wasn't as long ago as that; it's been only 9 months! :-) Sadly Skybuck probably ditched Python a long time ago as he was spending his time trying to make it into Java rather than taking advantage of idiomatic Python programming. Those that try to program Java style in Python are going to be frustrated. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python handles globals badly.
Now I want reflecting the latest answers: I have the position of a high-level view (cause of lack of Python knowledge internals and compiler stuff, but also cause I think a language should be as far as possible user-friendly without knowing too much internals, and yes clearly cause of knowing OO-languages where I do not need such code-contamination) So, my high-level understanding of the "global"-keyword so far is: Give write access to a global var if this is set to this var inside a current code block. And this specific syntax construction is probably defined not cause it is really needed but cause it is assumed to help the developer avoiding mistakes, which I think is too much over-regulation. But from the answers given I maybe have to rethink about the global keyword. It seems to be an absolute need from low-level point of view - meaning the designer had no other choice as to invent the keyword "global": Two main reasons for the need of keyword "global" have been posted: Compiler - Python compiler or compiler at all cannot hide this from the developer? (It seems really a scripting problem. PHP has it, LUA has it vice versa, ...) Although I cannot really believe it, that technical reasons lead to this design. E.g recognizing if it is local or global: If this would be under the developer responsibility than this is simply achieved by giving well-written var names. And a compiler can surely recognize if a defined var xxx outside is not a var yyy inside a function. Or does anyone really name a global var xxx and a function var xxx? I am sure no one at all will do it. I dont want read such a code. Function calls (?) - I have to admit I did not really get the problematic from the sample provided by Chris Angelico. What I can see or mean to see is: it has nothing to do with global-keyword from the high level point of view: give write access, probably to the vars word and otherword. And yes, I see the vars independant. And cause you set no "global" they are simple local vars (readable+writeable) This is more about let me assume function call stack and closures things(?) which I think is handled automatically. But as said - here I cannot really respond. This have to be answered from more experienced users. My conclusion: -- My intention was to bring this into discussion and see what comes out and see what are the reasons for this keyword. I am not the user who can open the PEP, but maybe the community out decides to do so. But if this two problems really exists from low-level point of view, then ok, there is no other way than to use this keyword "global". I have not the experience to answer that. I can accept low-level problems if so. But then I ask you from high-level point of view (if my high level view is correct at all): Would you remove this keyword if it would be technically possible or is good for you from high level point of view to have a keyword "global"? My answer is clear: remove it. [The same e.g. with switch statement: add it] Then this is my question now! Thanks. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python handles globals badly.
On Thu, Sep 3, 2015 at 1:05 PM, wrote: > If this would be under the developer responsibility than this > is simply achieved by giving well-written var names. So, adopt a rule whereby you prefix all your global variable names with "global" or "g_"? How is this superior to just declaring them once per function that needs to set them? You're just shifting the extra typing from one place to another. > Or does anyone really name a global var xxx and a function var xxx? > I am sure no one at all will do it. I dont want read such a code. Intentionally, it's probably rare. But if I'm adding a new variable, I shouldn't need to first make sure that it's safe to do so by scanning over the entire file to make sure that the name hasn't already been used elsewhere in the opposite scope. > Function calls (?) - >I have to admit I did not really get the problematic from >the sample provided by Chris Angelico. > >What I can see or mean to see is: >it has nothing to do with global-keyword from the high level point of >view: give write access, probably to the vars word and otherword. > >And yes, I see the vars independant. >And cause you set no "global" they are simple local vars >(readable+writeable) So in order for something to be global, it would have to be referenced at least once in the global scope? Currently it's possible to do this: def set_foo(value): global foo foo = value def get_foo(): return foo With your proposal that would change to: foo = None def set_foo(value): foo = value def get_foo(): return foo So again the declaration has just been moved from one place to another. > But then I ask you from high-level point of view > (if my high level view is correct at all): > Would you remove this keyword if it would be technically possible > or is good for you from high level point of view to have a keyword "global"? Provided that the proposal doesn't open up the possibility of unintentionally creating a global variable where I wanted a local, I'd be okay with it. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python handles globals badly.
On Thu, Sep 3, 2015 at 1:47 PM, Ian Kelly wrote:
> On Thu, Sep 3, 2015 at 1:05 PM, wrote:
>
>> But then I ask you from high-level point of view
>> (if my high level view is correct at all):
>> Would you remove this keyword if it would be technically possible
>> or is good for you from high level point of view to have a keyword "global"?
>
> Provided that the proposal doesn't open up the possibility of
> unintentionally creating a global variable where I wanted a local, I'd
> be okay with it.
Let me clarify that I'd be okay with making the keyword optional. It
should probably still be kept around for the occasional use like this:
exec("""def function():
global {0}
{0} = 42
""".format('x'))
where the compiler would have little hope of figuring out that the
variable was meant to be global without it.
--
https://mail.python.org/mailman/listinfo/python-list
Re: XML Binding
Hello, On 09/03/15 19:54, Palpandi wrote: > Hi All, > > Is there any module available in python standard library for XML binding? If > not, any other suggestions. lxml is the right xml library to use. You can use lxml's objectify or Spyne. Here are some examples: http://stackoverflow.com/questions/19545067/python-joining-and-writing-xml-etrees-trees-stored-in-a-list > Which is good for parsing large file? > 1. XML binding > 2. Creating our own classes If you're dealing with huge files, I suggest using just lxml and work with raw data. Deserializing xml objects to python classes sure is nicer but has performance overhead that gets more and more visible as the amount of data you deal with grows. Best, Burak -- https://mail.python.org/mailman/listinfo/python-list
Re: Reading \n unescaped from a file
On 09/03/2015 06:12 PM, Rob Hills wrote:
Hi Friedrich,
On 03/09/15 16:40, Friedrich Rentsch wrote:
On 09/02/2015 04:03 AM, Rob Hills wrote:
Hi,
I am developing code (Python 3.4) that transforms text data from one
format to another.
As part of the process, I had a set of hard-coded str.replace(...)
functions that I used to clean up the incoming text into the desired
output format, something like this:
dataIn = dataIn.replace('\r', '\\n') # Tidy up linefeeds
dataIn = dataIn.replace('<','<') # Tidy up < character
dataIn = dataIn.replace('>','>') # Tidy up < character
dataIn = dataIn.replace('o','o') # No idea why but lots of
these: convert to 'o' character
dataIn = dataIn.replace('f','f') # .. and these: convert to
'f' character
dataIn = dataIn.replace('e','e') # .. 'e'
dataIn = dataIn.replace('O','O') # .. 'O'
These statements transform my data correctly, but the list of statements
grows as I test the data so I thought it made sense to store the
replacement mappings in a file, read them into a dict and loop through
that to do the cleaning up, like this:
with open(fileName, 'r+t', encoding='utf-8') as mapFile:
for line in mapFile:
line = line.strip()
try:
if (line) and not line.startswith('#'):
line = line.split('#')[:1][0].strip() # trim
any trailing comments
name, value = line.split('=')
name = name.strip()
self.filterMap[name]=value.strip()
except:
self.logger.error('exception occurred parsing
line [{0}] in file [{1}]'.format(line, fileName))
raise
Elsewhere, I use the following code to do the actual cleaning up:
def filter(self, dataIn):
if dataIn:
for token, replacement in self.filterMap.items():
dataIn = dataIn.replace(token, replacement)
return dataIn
My mapping file contents look like this:
\r = \\n
â = "
< = <
> = >
' = '
F = F
o = o
f = f
e = e
O = O
This all works "as advertised" */except/* for the '\r' => '\\n'
replacement. Debugging the code, I see that my '\r' character is
"escaped" to '\\r' and the '\\n' to 'n' when they are read in from
the file.
I've been googling hard and reading the Python docs, trying to get my
head around character encoding, but I just can't figure out how to get
these bits of code to do what I want.
It seems to me that I need to either:
* change the way I represent '\r' and '\\n' in my mapping file; or
* transform them somehow when I read them in
However, I haven't figured out how to do either of these.
TIA,
I have had this problem too and can propose a solution ready to run
out of my toolbox:
class editor:
def compile (self, replacements):
targets, substitutes = zip (*replacements)
re_targets = [re.escape (item) for item in targets]
re_targets.sort (reverse = True)
self.targets_set = set (targets)
self.table = dict (replacements)
regex_string = '|'.join (re_targets)
self.regex = re.compile (regex_string, re.DOTALL)
def edit (self, text, eat = False):
hits = self.regex.findall (text)
nohits = self.regex.split (text)
valid_hits = set (hits) & self.targets_set # Ignore targets
with illegal re modifiers.
if valid_hits:
substitutes = [self.table [item] for item in hits if item
in valid_hits] + [] # Make lengths equal for zip to work right
if eat:
output = ''.join (substitutes)
else:
zipped = zip (nohits, substitutes)
output = ''.join (list (reduce (lambda a, b: a + b,
[zipped][0]))) + nohits [-1]
else:
if eat:
output = ''
else:
output = input
return output
substitutions = (
('\r', '\n'),
('<', '<'),
('>', '>'),
('o', 'o'),
('f', 'f'),
('e', 'e'),
('O', 'O'),
)
Order doesn't matter. Add new ones at the end.
e = editor ()
e.compile (substitutions)
A simple way of testing is running the substitutions through the editor
print e.edit (repr (substitutions))
(('\r', '\n'), ('<', '<'), ('>', '>'), ('o', 'o'), ('f', 'f'), ('e',
'e'), ('O', 'O'))
The escapes need to be tested separately
print e.edit ('abc\rdef')
abc
def
Note: This editor's compiler compiles the substitution list to a
regular expression which the editor uses to find all matches in the
text passed to edit. There has got to be a limit to the size of a text
which a regular expression can handle. I don't know what this limit
is. To be on the safe side, edit a large text line by line or at least
in sensible chunks.
Frederic
Thanks for the suggestion. I had originally done a simple set of
hard-coded str.rep
Re: How do I real a SSL certs serial number using Python?
Is this a good enough point? https://pyopenssl.readthedocs.org/en/stable/api/crypto.html?highlight=serial%20number#OpenSSL.crypto.X509.get_serial_number Write back if you need more help. Laura -- https://mail.python.org/mailman/listinfo/python-list
Re: Python handles globals badly.
On 03/09/2015 20:47, Ian Kelly wrote: On Thu, Sep 3, 2015 at 1:05 PM, wrote: Or does anyone really name a global var xxx and a function var xxx? I am sure no one at all will do it. I dont want read such a code. Intentionally, it's probably rare. But if I'm adding a new variable, I shouldn't need to first make sure that it's safe to do so by scanning over the entire file to make sure that the name hasn't already been used elsewhere in the opposite scope. I'm just curious as I've never used it myself, but how does nonlocal https://docs.python.org/3/reference/simple_stmts.html#the-nonlocal-statement fit into this? -- 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
Need Help w. PIP!
Well I hjave certainly noted more than once that pip is cont ained in Python 3.4. But I am having the most extreme problems with simply typing "pip" into my command prompt and then getting back the normal information on pip! I have repeatedly downloaded [to my Desktop] that get-pip.py file then ran it. I even downloaded that easy-install.py and ran that but to no success! I have all of the proper env. variables set. Can someone please help me? -- https://mail.python.org/mailman/listinfo/python-list
Re: Porting Python Application to a new linux machine
In a message of Thu, 03 Sep 2015 07:32:55 -0700, Heli Nix writes: >Dear all, > >I have my python scripts that use several python libraries such as h5py, >pyside, numpy > >In Windows I have an installer that will install python locally on user >machine and so my program gets access to this local python and runs >successfully. > >How can I do this in Linux ? ( I want to install python plus my program on the >user machine.) I do not want to use the user´s python or to install python on >the user´s machine on root. > >Thanks in Advance for your help, There are several approaches here. One is to get your users to run things in a virtualenv. see:https://virtualenv.pypa.io/en/latest/ and https://virtualenvwrapper.readthedocs.org/en/latest/ This works really well, but you have to have users who are capable of setting up a virtualenv in the first place. You will still run into problems of 'my shared library is different from your shared library'. YOu can also use PyInstaller (which you may have used to make windows binaries) to make linux ones. I've never done this, only made windows ones -- but that is what it says on the label. https://github.com/pyinstaller/pyinstaller/wiki I think you will still have to have a set of different files to download for different linux distributions, but I could be wrong about that. And if that problem is unacceptable, then you need docker. https://www.docker.com/ I've just started playing with it, and I think it is really neat, but it is too soon for me to have any clue what the problems/tradeoffs are with it. Laura -- https://mail.python.org/mailman/listinfo/python-list
Re: Python handles globals badly.
On Thu, Sep 3, 2015 at 4:13 PM, Mark Lawrence wrote: > On 03/09/2015 20:47, Ian Kelly wrote: >> >> On Thu, Sep 3, 2015 at 1:05 PM, wrote: >>> >>> Or does anyone really name a global var xxx and a function var xxx? >>> I am sure no one at all will do it. I dont want read such a code. >> >> >> Intentionally, it's probably rare. But if I'm adding a new variable, I >> shouldn't need to first make sure that it's safe to do so by scanning >> over the entire file to make sure that the name hasn't already been >> used elsewhere in the opposite scope. >> > > I'm just curious as I've never used it myself, but how does nonlocal > https://docs.python.org/3/reference/simple_stmts.html#the-nonlocal-statement > fit into this? I don't know whether the proposal also applies to nonlocals, but such conflicts would be less of an issue since you would only need to check the outermost function scope (and also, nested functions aren't really all that common). -- https://mail.python.org/mailman/listinfo/python-list
Re: Strange location for a comma
On 03.09.2015 14:20, ast wrote:
Hello,
At the end of the last line of the following program,
there is a comma, I dont understand why ?
Thx
from cx_Freeze import setup, Executable
# On appelle la fonction setup
setup(
name = "salut",
version = "0.1",
description = "Ce programme vous dit bonjour",
executables = [Executable("salut.py")],# <--- HERE
)
I know of several projects having this convention because when using a
repository software like git, it leads to smaller and thus more readable
diffs.
Best,
Sven
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python handles globals badly.
On 03.09.2015 00:25, [email protected] wrote: It is the good idea of Python about modules which are singletons and therefore have already its state (so in some way they are already somehow like classes - except the bad annoying thing with the "global" statement). So, what you really want is a better language support for singletons? -- https://mail.python.org/mailman/listinfo/python-list
Re: packing unpacking depends on order.
On 03.09.2015 03:17, [email protected] wrote: The question is what does "assign it to the left side at once" even *mean* in the presence of subscripts? Build up a list of object-subscript pairs (evaluating all the subscripts, including if any may have side effects) before executing any __setitem__? I think Ian described how it could be done. Why is the right side evaluated first? Because that's how things normally work. Evaluate the RHS and assign the value to the LHS. Currently, the generalization of a simple assignment is more like hopping back and forth around the "=". You mentioned side-effects. That is true. Right now, however, the side-effects even fire back to the RHS of the assignment. That is really weird. To me, and as it seems to some other folks here, the RHS should be at least independent of the LHS and vice versa. Both sides may have side-effects, but at least independently from each other. That's at least how I feel about it. Best, Sven -- https://mail.python.org/mailman/listinfo/python-list
Re: Need Help w. PIP!
On 03/09/2015 23:20, Steve Burrus wrote: Well I hjave certainly noted more than once that pip is cont ained in Python 3.4. But I am having the most extreme problems with simply typing "pip" into my command prompt and then getting back the normal information on pip! I have repeatedly downloaded [to my Desktop] that get-pip.py file then ran it. I even downloaded that easy-install.py and ran that but to no success! I have all of the proper env. variables set. Can someone please help me? As always my main and spare crystal balls are at the menders due to overwork, so I'll have to ask, what happened when you tried the 'pip', 'get-pip.py' and 'easy-install.py' commands? What OS are you on? -- 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: Python handles globals badly.
On 09/03/2015 01:05 PM, [email protected] wrote: > And a compiler can surely recognize if a defined var xxx outside is > not a var yyy inside a function. At issue here is the idea of Python namespaces and how Python uses them in a consistent way with your code. The consistency is that binding of a name to an object within a function is in the function's namespace. Makes things fast and simple. To facilitate writing to the module's namespace the global keyword is an elegant way of preserving consistency. But this has been said a few times I'm sure so we're going in circles here. > Or does anyone really name a global var xxx and a function var xxx? I > am sure no one at all will do it. Not sure I follow you here. What do the names programmers choose have to do with it? If I'm looking at a function, which should never be more than a screen of code long, if I see a reference to a variable that has never been assigned, I know it's defined in a parent scope. If I see as assignment, then I know it's local. If I see the word global then I know that any assignments are to the global namespace. Doesn't matter what the name is. It's consistent and explicit, which is one of Python's mantras, so I feel justified in defending this quirk/foible/feature of the language. > My answer is clear: remove it. But the global keyword serves a purpose. It's just different from the purpose you think you need. I get the impression you'd rather bend Python to your will, rather than work with it and learn the powerful Python idioms, which is just going to end in frustration. I don't think anyone would support a PEP to change python as you suggest (and it couldn't be done anytime soon until Python 4000 anyway). Seems a rather Quixote-esque quest you are on here. Spend some time to understand how Python variables differ from variables in other languages (most python "variables" are names bound to immutable objects like numbers). > [The same e.g. with switch statement: add it] Switch is a nice-to-have thing, but definitely not essential. A PEP here (probably already has been several) would at least be read anyway. However, there are several idiomatic ways of accomplishing the same thing that are often good enough and familiar to any Python programmer out there. Since functions are first-class objects, often a dispatch table is the best way to go here. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python handles globals badly.
On 04/09/2015 01:06, Michael Torrie wrote: On 09/03/2015 01:05 PM, [email protected] wrote: [The same e.g. with switch statement: add it] Switch is a nice-to-have thing, but definitely not essential. A PEP here (probably already has been several) would at least be read anyway. However, there are several idiomatic ways of accomplishing the same thing that are often good enough and familiar to any Python programmer out there. Since functions are first-class objects, often a dispatch table is the best way to go here. https://www.python.org/dev/peps/pep-3103/ "A Switch/Case Statement" by Guido van Rossum, "Rejection Notice - A quick poll during my keynote presentation at PyCon 2007 shows this proposal has no popular support. I therefore reject it". https://www.python.org/dev/peps/pep-0275/ "Switching on Multiple Values" by Marc-André Lemburg, "Rejection Notice - A similar PEP for Python 3000, PEP 3103 [2], was already rejected, so this proposal has no chance of being accepted either." -- 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: Need Help w. PIP!
On Thursday, September 3, 2015 at 7:06:27 PM UTC-5, Mark Lawrence wrote: > On 03/09/2015 23:20, Steve Burrus wrote: > > Well I hjave certainly noted more than once that pip is cont ained in > > Python 3.4. But I am having the most extreme problems with simply typing > > "pip" into my command prompt and then getting back the normal information > > on pip! I have repeatedly downloaded [to my Desktop] that get-pip.py file > > then ran it. I even downloaded that easy-install.py and ran that but to no > > success! I have all of the proper env. variables set. Can someone please > > help me? > > As always my main and spare crystal balls are at the menders due to > overwork, so I'll have to ask, what happened when you tried the 'pip', > 'get-pip.py' and 'easy-install.py' commands? What OS are you on? > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence I have tried the 'python get-pip.py' command over amnd over again in my command prompt and the 'python easy-install.py" command a little less. I swear I have set ALL of the env. variables correctly! My OS is Windows 10 Beta Preview Build 10074. -- https://mail.python.org/mailman/listinfo/python-list
Re: Need Help w. PIP!
On 2015-09-04 02:04, Steve Burrus wrote: On Thursday, September 3, 2015 at 7:06:27 PM UTC-5, Mark Lawrence wrote: On 03/09/2015 23:20, Steve Burrus wrote: > Well I hjave certainly noted more than once that pip is cont ained in Python 3.4. But I am having the most extreme problems with simply typing "pip" into my command prompt and then getting back the normal information on pip! I have repeatedly downloaded [to my Desktop] that get-pip.py file then ran it. I even downloaded that easy-install.py and ran that but to no success! I have all of the proper env. variables set. Can someone please help me? As always my main and spare crystal balls are at the menders due to overwork, so I'll have to ask, what happened when you tried the 'pip', 'get-pip.py' and 'easy-install.py' commands? What OS are you on? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence I have tried the 'python get-pip.py' command over amnd over again in my command prompt and the 'python easy-install.py" command a little less. I swear I have set ALL of the env. variables correctly! My OS is Windows 10 Beta Preview Build 10074. If you have Python 3.4, then you already have pip. It's in the "Scripts" subfolder of the Python 3.4 folder. -- https://mail.python.org/mailman/listinfo/python-list
Re: Need Help w. PIP!
On Fri, Sep 4, 2015 at 11:04 AM, Steve Burrus wrote: > I have tried the 'python get-pip.py' command over amnd over again in my > command prompt and the 'python easy-install.py" command a little less. I > swear I have set ALL of the env. variables correctly! My OS is Windows 10 > Beta Preview Build 10074. > What happens if you type "python -m pip" ? Or "python3 -m pip"? Does that invoke pip? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
No request in module urllib ?
Hi,
Python 3.2.3 (default, Jun 18 2015, 21:46:42)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib
>>> urllib.request.urlopen('http://example.org')
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'module' object has no attribute 'request'
Same error with Python 3.4.0
--
https://mail.python.org/mailman/listinfo/python-list
Re: No request in module urllib ?
On Fri, Sep 4, 2015 at 11:56 AM, Vincent Vande Vyvre
wrote:
> Python 3.2.3 (default, Jun 18 2015, 21:46:42)
> [GCC 4.6.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
import urllib
urllib.request.urlopen('http://example.org')
> Traceback (most recent call last):
> File "", line 1, in
> AttributeError: 'module' object has no attribute 'request'
>
> Same error with Python 3.4.0
With packages, like this, you sometimes need to explicitly import the
piece you want. That way, the urllib module doesn't have to load
everything up just because you wanted one small part. Try this
instead:
import urllib.request
urllib.request.urlopen('http://example.org')
Hope that helps!
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: packing unpacking depends on order.
On Fri, Sep 4, 2015 at 9:25 AM, Sven R. Kunze wrote: > Both sides may have side-effects, but at least independently from each > other. That's at least how I feel about it. You can't do that, though. Every piece of Python code can cause arbitrary code to execute, and unless you run them in separate interpreters, they can affect each other. So Python MUST have a well-defined order of evaluation. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Python handles globals badly.
On Fri, 4 Sep 2015 02:43 am, Michael Torrie wrote: > Sadly Skybuck probably ditched Python a long time ago "Sadly"? -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: No request in module urllib ?
Le 04/09/2015 04:08, Chris Angelico a écrit :
On Fri, Sep 4, 2015 at 11:56 AM, Vincent Vande Vyvre
wrote:
Python 3.2.3 (default, Jun 18 2015, 21:46:42)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import urllib
urllib.request.urlopen('http://example.org')
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'module' object has no attribute 'request'
Same error with Python 3.4.0
With packages, like this, you sometimes need to explicitly import the
piece you want. That way, the urllib module doesn't have to load
everything up just because you wanted one small part. Try this
instead:
import urllib.request
urllib.request.urlopen('http://example.org')
Hope that helps!
ChrisA
Thanks, that works with 3.4.0. No with 3.2.3
Vincent
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python handles globals badly.
On Fri, 4 Sep 2015 05:05 am, [email protected] wrote: > Or does anyone really name a global var xxx and a function var xxx? > I am sure no one at all will do it. I dont want read such a code. You should reflect on the purpose of namespaces and local variables. Some programming languages do not distinguish local and global variables. There are only variables, and they are shared by the entire program. That is terrible for encapsulation, because every time you use a variable, you have to stop and think whether that name is already being used *anywhere* else: def function(x): ... y = x + 1 What if y is being used somewhere else? You have just over-written the value of y that another part of the program relies on. Instead, most languages over the last 40 or 50 years have separate namespaces for variables. Each function's local variables are separate from every other function's locals: writing "y = x + 1" inside a function *cannot possibly* affect another function, if y is a local variable. So when writing a function, and creating local variables, you do not need to care whether the names you use have been used elsewhere. There is no need for every name in the entire program to be unique. The only time you need care is to avoid using the same name for a local and a global *that you intend to use*. If you don't intend to use it, there is no possible harm. Think about a program where last week I have written a function: def function(x): ... y = x + 1 y here is local to the function. Most commercial programs have dozens or hundreds of developers working on them (for something big like Microsoft Windows). Open source software might have thousands of developers. So today you come along and work on the same program as me, and you add a global variable: y = 999 What do you expect to happen? Do you think it is a good idea for your change *outside* of the function to suddenly change the meaning of the line "y = x + 1" *inside* the function? Fortunately, in Python, nothing changes. My function continues to work as before. You adding a global variable that happens to have the same name as one of my local variables does not break my function. Local variables are completely isolated to the function they are in. Which is exactly the way it should be. Worrying about local variables using the same name as globals is silly. The only time that is harmful is if you intend to use the global in a function but have a local of the same name. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: No request in module urllib ?
On Fri, Sep 4, 2015 at 12:17 PM, Vincent Vande Vyvre
wrote:
>> import urllib.request
>> urllib.request.urlopen('http://example.org')
>>
>
> Thanks, that works with 3.4.0. No with 3.2.3
Hmm, not sure why it wouldn't. According to the docs [1] it should be
available. But I don't have a 3.2 anywhere around me now, so I can't
check. (Steven D'Aprano no doubt can!) What happens when you try?
ImportError? AttributeError?
ChrisA
[1] https://docs.python.org/3.2/library/urllib.request.html
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python handles globals badly.
On Fri, 4 Sep 2015 05:05 am, [email protected] wrote: > Would you remove this keyword if it would be technically possible Absolutely not. I do not believe that it is technically possible, but even if it were, I would still argue that the Zen of Python applies: Explicit is better than implicit. Local variables should be the default, and you should explicitly declare any time you want to write to a global. Not the other way around, like Lua does. I've always thought that was silly: you should make the *desirable* thing easy to do, and the *dangerous* think (using globals) possible but not easy to do by accident. > or is good for you from high level point of view to have a keyword > "global"? Yes. > My answer is clear: remove it. > [The same e.g. with switch statement: add it] What would a switch statement do? How will it be different from if...elif? Out of the dozen or so different switch statements offered by other languages, which would you choose? -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: No request in module urllib ?
On 2015-09-04 03:17, Vincent Vande Vyvre wrote:
Le 04/09/2015 04:08, Chris Angelico a écrit :
On Fri, Sep 4, 2015 at 11:56 AM, Vincent Vande Vyvre
wrote:
Python 3.2.3 (default, Jun 18 2015, 21:46:42)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import urllib
urllib.request.urlopen('http://example.org')
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'module' object has no attribute 'request'
Same error with Python 3.4.0
With packages, like this, you sometimes need to explicitly import the
piece you want. That way, the urllib module doesn't have to load
everything up just because you wanted one small part. Try this
instead:
import urllib.request
urllib.request.urlopen('http://example.org')
Hope that helps!
ChrisA
Thanks, that works with 3.4.0. No with 3.2.3
It works for me with Python 3.2.5 on Windows.
--
https://mail.python.org/mailman/listinfo/python-list
Re: No request in module urllib ?
Le 04/09/2015 04:30, Chris Angelico a écrit :
On Fri, Sep 4, 2015 at 12:17 PM, Vincent Vande Vyvre
wrote:
import urllib.request
urllib.request.urlopen('http://example.org')
Thanks, that works with 3.4.0. No with 3.2.3
Hmm, not sure why it wouldn't. According to the docs [1] it should be
available. But I don't have a 3.2 anywhere around me now, so I can't
check. (Steven D'Aprano no doubt can!) What happens when you try?
ImportError? AttributeError?
ChrisA
[1] https://docs.python.org/3.2/library/urllib.request.html
Sorry, my fault, a typo in the import line.
Vincent
--
https://mail.python.org/mailman/listinfo/python-list
Re: Need Help w. PIP!
On 04/09/2015 02:55, Chris Angelico wrote: On Fri, Sep 4, 2015 at 11:04 AM, Steve Burrus wrote: I have tried the 'python get-pip.py' command over amnd over again in my command prompt and the 'python easy-install.py" command a little less. I swear I have set ALL of the env. variables correctly! My OS is Windows 10 Beta Preview Build 10074. What happens if you type "python -m pip" ? Or "python3 -m pip"? Does that invoke pip? ChrisA "python3 xyz" won't go on Windows. There are now three pip executables in the "Scripts" subfolder under the Python3.4 installation, pip.exe, pip3.exe and pip3.4.exe. -- 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: Need Help w. PIP!
On Fri, Sep 4, 2015 at 1:04 PM, Mark Lawrence wrote: > On 04/09/2015 02:55, Chris Angelico wrote: >> >> On Fri, Sep 4, 2015 at 11:04 AM, Steve Burrus >> wrote: >>> >>> I have tried the 'python get-pip.py' command over amnd over again in my >>> command prompt and the 'python easy-install.py" command a little less. I >>> swear I have set ALL of the env. variables correctly! My OS is Windows 10 >>> Beta Preview Build 10074. >>> >> >> What happens if you type "python -m pip" ? Or "python3 -m pip"? Does >> that invoke pip? >> >> ChrisA >> > > "python3 xyz" won't go on Windows. There are now three pip executables in > the "Scripts" subfolder under the Python3.4 installation, pip.exe, pip3.exe > and pip3.4.exe. Not sure what you mean by "won't go", but I was just curious about whether there was some pathing issue that meant that the Scripts subfolder wasn't accessible, yet the main Python binary might have been. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Need Help w. PIP!
On Thursday, September 3, 2015 at 8:55:52 PM UTC-5, Chris Angelico wrote: > On Fri, Sep 4, 2015 at 11:04 AM, Steve Burrus wrote: > > I have tried the 'python get-pip.py' command over amnd over again in my > > command prompt and the 'python easy-install.py" command a little less. I > > swear I have set ALL of the env. variables correctly! My OS is Windows 10 > > Beta Preview Build 10074. > > > > What happens if you type "python -m pip" ? Or "python3 -m pip"? Does > that invoke pip? > > ChrisA Well chris when I typed in"python -m pip" it worked but nopt with "python3 - m pip"! Why do you think that is? -- https://mail.python.org/mailman/listinfo/python-list
Re: Need Help w. PIP!
On 04/09/2015 02:04, Steve Burrus wrote: On Thursday, September 3, 2015 at 7:06:27 PM UTC-5, Mark Lawrence wrote: On 03/09/2015 23:20, Steve Burrus wrote: Well I hjave certainly noted more than once that pip is cont ained in Python 3.4. But I am having the most extreme problems with simply typing "pip" into my command prompt and then getting back the normal information on pip! I have repeatedly downloaded [to my Desktop] that get-pip.py file then ran it. I even downloaded that easy-install.py and ran that but to no success! I have all of the proper env. variables set. Can someone please help me? As always my main and spare crystal balls are at the menders due to overwork, so I'll have to ask, what happened when you tried the 'pip', 'get-pip.py' and 'easy-install.py' commands? What OS are you on? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence I have tried the 'python get-pip.py' command over amnd over again in my command prompt and the 'python easy-install.py" command a little less. I swear I have set ALL of the env. variables correctly! My OS is Windows 10 Beta Preview Build 10074. I'm awfully sorry, but my crystal balls still aren't back from the menders, so let's try again. Precisely explain what happened when you tried the 'pip', 'get-pip.py' and 'easy-install.py' commands? Could it have been nuclear holocaust, ice cream dripping down your shirt front, something like "pip isn't recognised as a Windows command", or whatever the wording actually is, or even a Python traceback, in which case please cut and paste it, in full, here? -- 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: Need Help w. PIP!
On Fri, Sep 4, 2015 at 1:07 PM, Steve Burrus wrote: > On Thursday, September 3, 2015 at 8:55:52 PM UTC-5, Chris Angelico wrote: >> On Fri, Sep 4, 2015 at 11:04 AM, Steve Burrus >> wrote: >> > I have tried the 'python get-pip.py' command over amnd over again in my >> > command prompt and the 'python easy-install.py" command a little less. I >> > swear I have set ALL of the env. variables correctly! My OS is Windows 10 >> > Beta Preview Build 10074. >> > >> >> What happens if you type "python -m pip" ? Or "python3 -m pip"? Does >> that invoke pip? >> >> ChrisA > > Well chris when I typed in"python -m pip" it worked but nopt with "python3 > - m pip"! Why do you think that is? As Mark says, you're forcing us to use our crystal balls here. Just whether or not something "worked" is not sufficient; what happened? In XKCD 722 terms, what is the pattern of lights, and what are you expecting it to be? If I had to guess, I would suspect a problem with pathing in your Python 3 installation. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: No request in module urllib ?
On 04/09/2015 03:30, Chris Angelico wrote:
On Fri, Sep 4, 2015 at 12:17 PM, Vincent Vande Vyvre
wrote:
import urllib.request
urllib.request.urlopen('http://example.org')
Thanks, that works with 3.4.0. No with 3.2.3
Hmm, not sure why it wouldn't. According to the docs [1] it should be
available. But I don't have a 3.2 anywhere around me now, so I can't
check. (Steven D'Aprano no doubt can!) What happens when you try?
ImportError? AttributeError?
ChrisA
[1] https://docs.python.org/3.2/library/urllib.request.html
If my understanding is correct, owing to the way the time machine works,
Steven still has Python versions -3.6 to -0.1 running.
--
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: Need Help w. PIP!
On 04/09/2015 04:08, Chris Angelico wrote: On Fri, Sep 4, 2015 at 1:04 PM, Mark Lawrence wrote: On 04/09/2015 02:55, Chris Angelico wrote: On Fri, Sep 4, 2015 at 11:04 AM, Steve Burrus wrote: I have tried the 'python get-pip.py' command over amnd over again in my command prompt and the 'python easy-install.py" command a little less. I swear I have set ALL of the env. variables correctly! My OS is Windows 10 Beta Preview Build 10074. What happens if you type "python -m pip" ? Or "python3 -m pip"? Does that invoke pip? ChrisA "python3 xyz" won't go on Windows. There are now three pip executables in the "Scripts" subfolder under the Python3.4 installation, pip.exe, pip3.exe and pip3.4.exe. Not sure what you mean by "won't go", but I was just curious about whether there was some pathing issue that meant that the Scripts subfolder wasn't accessible, yet the main Python binary might have been. ChrisA python3 just doesn't exist on Windows, it's always python.exe or pythonw.exe. Not that I'd recommend using them in this day and age, py.exe or pyw.exe and specify your version via the command line or a shebang line in your script is certainly my preferred way of doing things. -- 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: Need Help w. PIP!
On Fri, Sep 4, 2015 at 1:27 PM, Mark Lawrence wrote: > python3 just doesn't exist on Windows, it's always python.exe or > pythonw.exe. Not that I'd recommend using them in this day and age, py.exe > or pyw.exe and specify your version via the command line or a shebang line > in your script is certainly my preferred way of doing things. Ohh. My bad. Sorry, Steve, I led you astray! Silly Windows, making it hard for people to just guess and be right. :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: packing unpacking depends on order.
On Thu, Sep 3, 2015, at 19:25, Sven R. Kunze wrote: > You mentioned side-effects. That is true. Right now, however, the > side-effects even fire back to the RHS of the assignment. That is really > weird. To me, and as it seems to some other folks here, the RHS should > be at least independent of the LHS and vice versa. You haven't demonstrated that the RHS is affected by anything. The sample code in the original post of this thread behaves identically if the RHS is a simple tuple of (2, 1) [or (1, 2)] respectively. If you have another sample that shows different behavior please post it. -- https://mail.python.org/mailman/listinfo/python-list
Re: XML Binding
Thanks Burak. lmxl is good. But it is not supported with python 2.5. Any other option? -- https://mail.python.org/mailman/listinfo/python-list
Re: XML Binding
On Fri, Sep 4, 2015 at 3:21 PM, Palpandi wrote: > Thanks Burak. > > lmxl is good. But it is not supported with python 2.5. Any other option? The latest version isn't. But PyPI has an older version which is: https://pypi.python.org/pypi/lxml/3.3.6 You should be able to install that into a Python 2.5. Though if you possibly can, I would recommend upgrading to 2.7. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Porting Python Application to a new linux machine
Am 03.09.15 um 16:32 schrieb Heli Nix: I have my python scripts that use several python libraries such as h5py, pyside, numpy In Windows I have an installer that will install python locally on user machine and so my program gets access to this local python and runs successfully. How can I do this in Linux ? ( I want to install python plus my program on the user machine.) I do not want to use the user´s python or to install python on the user´s machine on root. Another variant is the use of pyinstaller. It can generate a single directory with a copy of Python and all needed libraries. You can copy that to a different machine, and often it works - unless libc or some very basic library is different. Beware that this pulls in half of your system, so you'll end up with ~100 MB. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Need Help w. PIP!
"Steve Burrus" a écrit dans le message de news:[email protected]... Well I hjave certainly noted more than once that pip is cont ained in Python 3.4. But I am having the most extreme problems with simply typing "pip" into my command prompt and then getting back the normal information on pip! I have repeatedly downloaded [to my Desktop] that get-pip.py file then ran it. I even downloaded that easy-install.py and ran that but to no success! I have all of the proper env. variables set. Can someone please help me? I am using python 3.4 on windows too and to run pip I just enter in a command window: py -m pip -- https://mail.python.org/mailman/listinfo/python-list
Re: Need Help w. PIP!
"ast" a écrit dans le message de news:[email protected]... "Steve Burrus" a écrit dans le message de news:[email protected]... Well I hjave certainly noted more than once that pip is cont ained in Python 3.4. But I am having the most extreme problems with simply typing "pip" into my command prompt and then getting back the normal information on pip! I have repeatedly downloaded [to my Desktop] that get-pip.py file then ran it. I even downloaded that easy-install.py and ran that but to no success! I have all of the proper env. variables set. Can someone please help me? I am using python 3.4 on windows too and to run pip I just enter in a command window: py -m pip Just typing 'pip' as you do does't work because pip.exe is located in Python\Scripts directory which in not included on variable %PATH% -- https://mail.python.org/mailman/listinfo/python-list
Re: Need Help w. PIP!
> Just typing 'pip' as you do does't work because pip.exe is located in Python\Scripts directory which in not included on variable %PATH% Is that new for win10? Just "pip" works fine on my win7 install. Although maybe I had to extend the path and forgot... - Nick On Fri, 4 Sep 2015 07:26 ast wrote: > > "ast" a écrit dans le message de > news:[email protected]... > > > > "Steve Burrus" a écrit dans le message de > > news:[email protected]... > > Well I hjave certainly noted more than once that pip is cont ained in > Python 3.4. But I am having > > the most extreme problems with simply typing "pip" into my command > prompt and then getting back > > the normal information on pip! I have repeatedly downloaded [to my > Desktop] that get-pip.py file > > then ran it. I even downloaded that easy-install.py and ran that but to > no success! I have all of > > the proper env. variables set. Can someone please help me? > > > > > > I am using python 3.4 on windows too and to run pip I just enter in a > command window: > > > > py -m pip > > > > Just typing 'pip' as you do does't work because pip.exe is located in > Python\Scripts > directory which in not included on variable %PATH% > > -- > https://mail.python.org/mailman/listinfo/python-list > -- - Nick -- https://mail.python.org/mailman/listinfo/python-list
Re: XML Binding
In a message of Thu, 03 Sep 2015 22:21:29 -0700, Palpandi writes: >Thanks Burak. > >lmxl is good. But it is not supported with python 2.5. Any other option? >-- >https://mail.python.org/mailman/listinfo/python-list check and see what python you have. If 2.6 or more recent, use lxml If you have 2.5 use the slower elementtree. https://docs.python.org/2/library/xml.etree.elementtree.html If you pay attention to this http://lxml.de/compatibility.html you can mostly get away with writing your code once. Laura -- https://mail.python.org/mailman/listinfo/python-list
Re: XML Binding
In a message of Fri, 04 Sep 2015 08:46:33 +0200, Laura Creighton writes: >In a message of Thu, 03 Sep 2015 22:21:29 -0700, Palpandi writes: >>Thanks Burak. >> >>lmxl is good. But it is not supported with python 2.5. Any other option? >>-- >>https://mail.python.org/mailman/listinfo/python-list > >check and see what python you have. If 2.6 or more recent, use lxml >If you have 2.5 use the slower elementtree. >https://docs.python.org/2/library/xml.etree.elementtree.html > >If you pay attention to this >http://lxml.de/compatibility.html >you can mostly get away with writing your code once. > >Laura I didn't know about the old versions still available from pip. That is probably a better idea. Laura -- https://mail.python.org/mailman/listinfo/python-list
