Re: Strange range

2016-04-03 Thread Marko Rauhamaa
Stephen Hansen :

> On Sat, Apr 2, 2016, at 02:40 PM, Marko Rauhamaa wrote:
>> That's why I was looking for counterexamples in the standard library
>
> This entire bent of an argument seems flawed to me.
>
> The standard library has never been a beacon for best practices or
> idiomatic uses of Python.

It's an obvious corpus of Python code not written by me that's readily
available on my computer. An argument was made that range() has varied
uses. I was trying to find those varied uses.

> That a use exists in the standard library, or that one does not,
> doesn't really tell you anything meaningful about Python itself or
> good practices with the language. The standard library is under
> uniquely conservative constraints that enshrine compatibility and
> reliability from one point release to another over any kind of
> innovation.

What you seem to be saying is that range() used to be an iterator but
has since ascended to the status of an iterable.

> Most code exists outside the stdlib.

Which should then make it easy for you to point out the kinds of
counterexamples I was looking for.


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


Re: Strange range

2016-04-03 Thread Chris Angelico
On Sun, Apr 3, 2016 at 4:43 PM, Stephen Hansen  wrote:
> The stdlib exists as a bastion of stability above all else. Its
> standards aren't a reason to make a change (or, not to make a change,
> either). That doesn't mean its not useful to look at the standard
> library, but you should not enshrine it as the example of good or
> idiomatic code to measure decisions against. Most code exists outside
> the stdlib.

Expanding on this: There have been times when the stdlib has been
cited in proposals, such as the introduction of a new keyword. Out of
five plausible words, two have significant use in the stdlib, another
has a couple of uses, and two more have no references at all. Specific
example from PEP 359 [1]; the same line of analysis has also been used
elsewhere. Also, a proposed new syntax can attempt to justify its
benefit by taking examples from the stdlib, not because they will
necessarily be changed, but simply because it's a good-sized codebase
that all Python devs and tinkerers will have easy access to. PEP 463
[2] demonstrates this. Similarly, but in reverse: The stdlib can
provide examples showing how a proposal will _break_ existing code,
and how it should be fixed; PEP 479 [3] has a few examples, some from
the stdlib, some hypothetical. In each case, the stdlib is being
treated as simply "a body of Python code", and one which has a measure
of neutrality (we're not favouring web app developers by looking at
the Django source code, or numeric computational work by looking at
Pandas, or anything like that), and if anything, it's indicative of
older codebases rather than newer ones, which is usually good for
proposals that need to be conservative.

So in the case of range() usage, I would say that stdlib usage showing
"x in range(...)" would be highly significant, but *absence* of such
usage is not.

ChrisA

[1] https://www.python.org/dev/peps/pep-0359/#keyword
[2] https://www.python.org/dev/peps/pep-0463/#example-usage
[3] https://www.python.org/dev/peps/pep-0479/#examples-of-breakage
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Strange range

2016-04-03 Thread Chris Angelico
On Sun, Apr 3, 2016 at 4:58 PM, Marko Rauhamaa  wrote:
>> That a use exists in the standard library, or that one does not,
>> doesn't really tell you anything meaningful about Python itself or
>> good practices with the language. The standard library is under
>> uniquely conservative constraints that enshrine compatibility and
>> reliability from one point release to another over any kind of
>> innovation.
>
> What you seem to be saying is that range() used to be an iterator but
> has since ascended to the status of an iterable.

No, range() has never returned an iterator. In Python 2, it returned a
list, which is iterable. In Python 3, it returns a range object, which
is iterable. And in Python 2, xrange returns an xrange object, which
is also iterable (but less functional than the Py3 range object). None
of these is an iterator.

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


Re: [beginner] What's wrong?

2016-04-03 Thread Thomas 'PointedEars' Lahn
Michael Torrie wrote:

> Mark, your messages are showing up to the list as being from "python,"
> at least on my email.  Any reason for this?

Depends on which Mark you are addressing and how you are reading e-mail.

The messages of Mark Lawrence, for example, appear to me as technically 
correct as can be expected from a botched Mail-to-News interface; in 
particular, their “From” header fields are correct.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Failed to update the os.environ with subprocess.Popen.

2016-04-03 Thread Cameron Simpson

On 03Apr2016 14:24, Steven D'Aprano  wrote:

On Sun, 3 Apr 2016 01:29 pm, Hongyi Zhao wrote:

I use the following code to update the os.environ with subprocess.Popen:


I don't understand what you are trying to do here. But regardless of your
intention, the problem you have is nothing to do with updating os.environ.
Proof: change the last line from this complicated expression:

os.environ.update(line.partition('=')[::2] for line in output.split('\0'))
to this simple expression:
output.split('\0')

and you will get the same error. os.environ is irrelevant. Your problem is
only with Popen.

What makes you think that Popen objects have a split() method? They are not
documented as having this method:

https://docs.python.org/2/library/subprocess.html
https://docs.python.org/3/library/subprocess.html
https://pymotw.com/2/subprocess/


In particular, you want the subprocess' output. As written, your code sets 
"output" to the Popen object. You actually want to set it to the .stdout 
attribute of that object, which is the output from the subcommand.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Failed to update the os.environ with subprocess.Popen.

2016-04-03 Thread Hongyi Zhao
On Sun, 03 Apr 2016 18:20:31 +1000, Cameron Simpson wrote:

> In particular, you want the subprocess' output. As written, your code
> sets "output" to the Popen object. You actually want to set it to the
> .stdout attribute of that object, which is the output from the
> subcommand.

Based on your above hints, I try to use the following codes:

output = Popen("""
/bin/bash <
os.environ.update(line.partition('=')[::2] for line in output.split
('\0'))
AttributeError: 'NoneType' object has no attribute 'split'


While the following code will work smoothly:

output = Popen("""
/bin/bash 

Re: [beginner] What's wrong?

2016-04-03 Thread Thomas 'PointedEars' Lahn
Rustom Mody wrote:

> On Saturday, April 2, 2016 at 10:42:27 PM UTC+5:30, Thomas 'PointedEars'
> Lahn wrote:
>> Marko Rauhamaa wrote:
>> > Steven D'Aprano :
>> >> So you're saying that learning to be a fluent speaker of English is a
>> >> pre-requisite of being a programmer?
>> > 
>> > No more than learning Latin is a prerequisite of being a doctor.
>> 
>> Full ACK.  Probably starting with the Industrial Revolution enabled by
>> the improvements of the steam machine in England, English has become the
>> /lingua franca/ of technology (even though the French often still
>> disagree, preferring words like « ordinateur » and « octet » over
>> “computer” and
>> “byte”, respectively¹).  (With the Internet at the latest, then, it has
>> also become the /lingua franca/ of science, although Latin terms are
>> common in medicine.)
> 
> IMHO the cavalier usage of random alphabet-soup for identifiers

Straw man.  Nobody has suggested that.  Suggested were words in natural 
languages other than English as (parts of) names in Python programs.

The suggestion was rejected by some (including me) on the grounds that 
source code is not written only for the person writing it, but also for 
other developers to read, and that English is the /lingua franca/ of 
software development at least.  So it is reasonable to expect a software 
developer to understand English, and more software developers are going to 
understand the source code if it is written in English.

Another argument that was made in favor of English-language names (albeit on 
the grounds of “nausea” instead of the logical reason of practicality) is 
that the (Python) programming language’s keywords (e.g., False, None, True, 
and, as, assert [1]) and built-in identifiers (e.g., NotImplemented, 
Ellipsis, abs, all, int, float, complex, iterator [2]) are (abbreviations or 
concatenations of) *English* words; therefore, mixing keywords with names
in a natural language other than English causes source code to be more 
difficult to read than an all-English source code (string values 
notwithstanding).  This is particularly true with Python because a lot of 
(well-written) Python code can easily be read as if it were pseudocode.  (I 
would not be surprised at all to learn that this was Guido van Rossum’s 
intention.)

As for the “Chinese” argument, I did some research recently, indicating that 
it is a statistical fallacy:




From personal experience, I can say that I had no great difficulty 
communicating in English with my Chinese flatmates and classmates at a 
German technical university when all of us were studying computer science 
there 16 years ago.  It was natural.  At least the boys even preferred self-
chosen English first names for themselves (e.g., in instant messaging) 
since, as they explained to me, their original names were difficult to 
pronounce correctly for Europeans (or Europeans might mistakenly call them 
by their family name since it would come first), and to type on European 
keyboards (although I observed them to be proficient in using IMEs when 
chatting with their folks back home).


[1] 
[2] 

> can lead to worse than just aesthetic unpleasantness:
> https://en.wikipedia.org/wiki/IDN_homograph_attack

Relevance?

> When python went to full unicode identifers it should have also added
> pragmas for which blocks the programmer intended to use -- something like
> a charset declaration of html.
> 
> This way if the programmer says "I want latin and greek"
> and then A and Α get mixed up well he asked for it.
> If he didn't ask then springing it on him seems unnecessary and uncalled
> for

Nonsense.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [beginner] What's wrong?

2016-04-03 Thread alister
On Sun, 03 Apr 2016 02:04:05 +0100, Mark Lawrence wrote:

> On 03/04/2016 01:48, Steven D'Aprano wrote:
>> On Sun, 3 Apr 2016 07:42 am, Michael Selik wrote:
>>
>>> Gaming also helps your reaction time. Normally 0.3 ms, but 0.1 ms for
>>> top gamers. And fighter pilots.
>>
>> Does gaming help reaction time, or do only people with fast reaction
>> times become top gamers?
>>
>> Personally, in my experience gaming hurts reaction time. I ask people a
>> question, and they don't reply for a week or at all, because they're
>> too busy playing games all day.
>>
>>
> I must agree.  When you're trying to get the ball away, and 23 stone of
> bone and muscle smashes into you, that slows your reaction time.  I am
> of course referring to the sport of rugby, not that silly "World
> Series", which takes part in only one country, where for some reason
> unknown to me they wear huge quantities of armour and need oxygen masks
> after they've run a few yards.  What would happen to the poor little
> darlings if they had to spend the entire match on the pitch?

while i agree with your sentiments you have a few minor inacuracies

the "World Series" has nothing to do with Poofs In Pads, it is actually 
Rounders. 



-- 
Real programmers don't write in BASIC.  Actually, no programmers write in
BASIC after reaching puberty.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [beginner] What's wrong?

2016-04-03 Thread Rustom Mody
On Sunday, April 3, 2016 at 5:17:36 PM UTC+5:30, Thomas 'PointedEars' Lahn 
wrote:
> Rustom Mody wrote:
> 
> > On Saturday, April 2, 2016 at 10:42:27 PM UTC+5:30, Thomas 'PointedEars'
> > Lahn wrote:
> >> Marko Rauhamaa wrote:
> >> > Steven D'Aprano :
> >> >> So you're saying that learning to be a fluent speaker of English is a
> >> >> pre-requisite of being a programmer?
> >> > 
> >> > No more than learning Latin is a prerequisite of being a doctor.
> >> 
> >> Full ACK.  Probably starting with the Industrial Revolution enabled by
> >> the improvements of the steam machine in England, English has become the
> >> /lingua franca/ of technology (even though the French often still
> >> disagree, preferring words like « ordinateur » and « octet » over
> >> “computer” and
> >> “byte”, respectively¹).  (With the Internet at the latest, then, it has
> >> also become the /lingua franca/ of science, although Latin terms are
> >> common in medicine.)
> > 
> > IMHO the cavalier usage of random alphabet-soup for identifiers
> 
> Straw man.  Nobody has suggested that.  Suggested were words in natural 
> languages other than English as (parts of) names in Python programs.
> 
> The suggestion was rejected by some (including me) on the grounds that 
> source code is not written only for the person writing it, but also for 
> other developers to read, and that English is the /lingua franca/ of 
> software development at least.  So it is reasonable to expect a software 
> developer to understand English, and more software developers are going to 
> understand the source code if it is written in English.
> 
> Another argument that was made in favor of English-language names (albeit on 
> the grounds of “nausea” instead of the logical reason of practicality) is 
> that the (Python) programming language’s keywords (e.g., False, None, True, 
> and, as, assert [1]) and built-in identifiers (e.g., NotImplemented, 
> Ellipsis, abs, all, int, float, complex, iterator [2]) are (abbreviations or 
> concatenations of) *English* words; therefore, mixing keywords with names
> in a natural language other than English causes source code to be more 
> difficult to read than an all-English source code (string values 
> notwithstanding).  This is particularly true with Python because a lot of 
> (well-written) Python code can easily be read as if it were pseudocode.  (I 
> would not be surprised at all to learn that this was Guido van Rossum’s 
> intention.)
> 
> As for the “Chinese” argument, I did some research recently, indicating that 
> it is a statistical fallacy:
> 
> 
> 
> 
> From personal experience, I can say that I had no great difficulty 
> communicating in English with my Chinese flatmates and classmates at a 
> German technical university when all of us were studying computer science 
> there 16 years ago.  It was natural.  At least the boys even preferred self-
> chosen English first names for themselves (e.g., in instant messaging) 
> since, as they explained to me, their original names were difficult to 
> pronounce correctly for Europeans (or Europeans might mistakenly call them 
> by their family name since it would come first), and to type on European 
> keyboards (although I observed them to be proficient in using IMEs when 
> chatting with their folks back home).
> 
> 
> [1] 
> [2] 
> 
> > can lead to worse than just aesthetic unpleasantness:
> > https://en.wikipedia.org/wiki/IDN_homograph_attack
> 
> Relevance?
> 
> > When python went to full unicode identifers it should have also added
> > pragmas for which blocks the programmer intended to use -- something like
> > a charset declaration of html.
> > 
> > This way if the programmer says "I want latin and greek"
> > and then A and Α get mixed up well he asked for it.
> > If he didn't ask then springing it on him seems unnecessary and uncalled
> > for
> 
> Nonsense.

Some misunderstanding of what I said it looks
[Guessing also from Marko's "...silly..."]

So here are some examples to illustrate what I am saying:

Example 1 -- Ligatures:

Python3 gets it right
>>> flag = 1
>>> flag
1

Whereas haskell gets it wrong:
Prelude> let flag = 1
Prelude> flag

:3:1: Not in scope: ‘flag’
Prelude> flag
1
Prelude> 

Example 2 Case Sensitivity
Scheme¹ gets it right

> (define a 1)
> A
1
> a
1

Python gets it wrong
>>> a=1
>>> A
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'A' is not defined
>>> a

[Likewise filenames windows gets right; Unix wrong]

Unicode Identifiers in the spirit of IDN homograph attack.
Every language that 'supports' unicode gets it wrong

Python3
>>> A=1
>>> Α
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'Α' is not defined
>>> A
1


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread Loop.IO
On Sunday, April 3, 2016 at 1:12:23 AM UTC+1, BartC wrote:
> On 02/04/2016 23:31, Loop.IO wrote:
> 
> > Oh i see, so the code prompts for a name.. so i'm more lost than i thought, 
> > what do I need to change to make it just create the file with the chosen 
> > name Launch2.bat without the prompt?
> 
> If you don't want the user to enter anything, then I explained how 
> before, just use:
> 
>   name='C:\\Documents\\PythonCoding\\launch2.bat'
> 
> if that's the file name you need.
> 
> -- 
> Bartc

Hi Bartc, i tried that, didn't work
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread Loop.IO
On Sunday, April 3, 2016 at 1:08:59 AM UTC+1, Mark Lawrence wrote:
> On 02/04/2016 23:23, Loop.IO wrote:
> > On Saturday, April 2, 2016 at 11:09:13 PM UTC+1, BartC wrote:
> >> On 02/04/2016 22:59, Loop.IO wrote:
> >>> Hey
> >>>
> >>> So I built a keylogger using python as a test, got the code from the 
> >>> tutorial online, I want to improve on it to make it more automated, but 
> >>> the issue I'm having is it won't create the file until I press return, 
> >>> any clues where I'm going wrong?
> >>>
> >>> If I press return it makes the batch file, otherwise it just hangs.
> >>
> >>>   name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat'
> >>
> >> You're asking for a file name to be entered. So that if ABC is pressed,
> >> followed by Enter, it will use:
> >>
> >> C:\Documents\PythonCoding\ABClaunch2.bat
> >>
> >> Assuming that's the intention, then Enter is needed so that it knows
> >> when the user has completed typing the name. If not, then just use:
> >>
> >> name='C:\\Documents\\PythonCoding\\launch2.bat'
> >>
> >> (If you want a single character name, without pressing Enter, that's
> >> harder to do. Someone else will have to help.)
> >>
> >> --
> >> Bartc
> >
> > Hey Bartc
> >
> > I don't quite understand what you mean?
> >
> > The file is just supposed to be created, I don't want to have to press 
> > "Enter" or "Return" for it to complete the file creation
> >
> > the info i followed to create the file advised I had to add the file name 
> > and extension on after like in the code
> >
> 
> There is no point asking BartC about Python as he has repeatedly stated 
> that he knows nothing about Python.  OTOH there are loads of people here 
> who do know Python, backwards, sideways and inside out.  If you state 
> precisely what you are trying to achieve then you will get the correct 
> answer.
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

Hi Mark

Basically I want the program to do the search, which it does fine, then create 
the batch file then close.

What I will be doing once thats fixed is then adding a write to the batch file 
some lines of code, which im already testing and seems to work fine, its just 
the having to press enter to create the file and then close the program
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [beginner] What's wrong?

2016-04-03 Thread Rustom Mody
On Sunday, April 3, 2016 at 5:19:33 AM UTC+5:30, Steven D'Aprano wrote:
> On Sun, 3 Apr 2016 03:12 am, Thomas 'PointedEars' Lahn wrote:
> 
> > Marko Rauhamaa wrote:
> > 
> >> Steven D'Aprano :
> >>> So you're saying that learning to be a fluent speaker of English is a
> >>> pre-requisite of being a programmer?
> >> 
> >> No more than learning Latin is a prerequisite of being a doctor.
> > 
> > Full ACK.  Probably starting with the Industrial Revolution enabled by the
> > improvements of the steam machine in England, English has become the
> > /lingua franca/ of technology (even though the French often still
> > disagree, preferring words like << ordinateur >> and << octet >> over
> > "computer" and "byte", respectively¹).  (With the Internet at the latest,
> > then, it has also become the /lingua franca/ of science, although Latin
> > terms are common in medicine.)
> 
> And this is a BAD THING. Monoculture is harmful, and science and technology
> is becoming a monoculture: Anglo-American language expressing
> Anglo-American ideas, regardless of the nationality of the scientist or
> engineer.

I think you are ending making the opposite point of what you seem to want to 
make
Yeah... ok monoculture is a bad thing.
Is python(3) helping towards a 'polyculture'?

To see this consider some app like Word or Gimp that has significant 
functionality and has a history over 20 years.

So let us say some 10 years ago it was internationalized.
This consists of 
1. Rewriting the 'strings' into gettext (or whatever) form along with other
program reorgs
2. Translators actually translating the 'strings'

Or take a modern OS like Windows or Ubuntu -- from the first install screen
we can pick a language and then it will be localized to that

To really localize python one would have to
1. Localize the keywords
2. Localize all module names
3. Localize all the help strings
4. Localize the entire stuff up at https://docs.python.org/3/
5. ...

That is probably one or two orders of magnitude more work than
localizing gimp or Word

So if this is the full goal how far does
"You can now spell (or misspell) your python identifiers in any language of 
your choice"
go towards that goal?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread BartC

On 03/04/2016 15:41, Loop.IO wrote:

On Sunday, April 3, 2016 at 1:12:23 AM UTC+1, BartC wrote:

On 02/04/2016 23:31, Loop.IO wrote:


Oh i see, so the code prompts for a name.. so i'm more lost than i thought, 
what do I need to change to make it just create the file with the chosen name 
Launch2.bat without the prompt?


If you don't want the user to enter anything, then I explained how
before, just use:

   name='C:\\Documents\\PythonCoding\\launch2.bat'

if that's the file name you need.

--
Bartc


Hi Bartc, i tried that, didn't work


You mean it gave an error when you tried to create that file?

Does that path already exist on your machine? If not then trying to 
create a file in a non-existent path won't work.


You can create the path manually outside of Python. Or look up the docs 
to find out how to do that. A quick google suggested using os.makedirs 
(to create multiple nested paths at the same time).


The following code worked on my machine:

import sys
import os

def create():
print("creating new file")

path="c:/Documents/PythonCoding/"
name=path+"launch2.bat"

try:
os.stat(path)
except:
os.makedirs(path)

print (name)

try:
file=open(name,'w')
file.close()
except:
print("error occured")
sys.exit(0)

create()

--
Bartc


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


Re: [beginner] What's wrong?

2016-04-03 Thread Dan Sommers
On Sun, 03 Apr 2016 07:30:47 -0700, Rustom Mody wrote:

> So here are some examples to illustrate what I am saying:

[A vs a, A vs A, flag vs flag, etc.]

Are identifiers text or bytes? or something else entirely that takes
natural language rules and the appearance of the glyphs into account?

I, for one, am very happy that identifiers are more like bytes than like
they are like text.  The rules for equality for sequences of bytes are
well-defined and unambiguous.  The rules for equality for text are not.
Do I have to know the details of every human (and some non-human)
language, not to mention their typographical conventions (e.g.,
ligatures) just to determine whether two identifiers are the same?

Yes, it's marginally annoying, and a security hole waiting to happen,
than A and A often look very much alike.  It's also troubling that I, a
native English speaker with some knowledge of a random selection of
other languages, should know whether e and é are the same, or whether ij
and ij are the same, and that it might depend on the fonts that happen to
have been used to render them.

And where does it end?  If flag and flag are the same, then are Omega and
Ω the same?

In English (and many other languages), it is wrong to spell my first
name with an initial lower case letter.  Therefore, Dan and dan are not,
and should not be, the same identifier.

ObPython:  if my identifiers are case-insensitive, then what about the
language's keywords?  Can I spell class and for as Class and For?

I understand that in some use cases, flag and flag represent the same
English word, but please don't extend that to identifiers in my
software.

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


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread Rustom Mody
On Sunday, April 3, 2016 at 8:41:49 PM UTC+5:30, BartC wrote:
> On 03/04/2016 15:41, Loop.IO wrote:
> > On Sunday, April 3, 2016 at 1:12:23 AM UTC+1, BartC wrote:
> >> On 02/04/2016 23:31, Loop.IO wrote:
> >>
> >>> Oh i see, so the code prompts for a name.. so i'm more lost than i 
> >>> thought, what do I need to change to make it just create the file with 
> >>> the chosen name Launch2.bat without the prompt?
> >>
> >> If you don't want the user to enter anything, then I explained how
> >> before, just use:
> >>
> >>name='C:\\Documents\\PythonCoding\\launch2.bat'
> >>
> >> if that's the file name you need.
> >>
> >> --
> >> Bartc
> >
> > Hi Bartc, i tried that, didn't work
> 
> You mean it gave an error when you tried to create that file?
> 
> Does that path already exist on your machine? If not then trying to 
> create a file in a non-existent path won't work.
> 
> You can create the path manually outside of Python. Or look up the docs 
> to find out how to do that. A quick google suggested using os.makedirs 
> (to create multiple nested paths at the same time).
> 
> The following code worked on my machine:
> 
> import sys
> import os
> 
> def create():
>   print("creating new file")
> 
>   path="c:/Documents/PythonCoding/"
>   name=path+"launch2.bat"
> 
>   try:
>   os.stat(path)
>   except:
>   os.makedirs(path)
> 
>   print (name)
> 
>   try:
>   file=open(name,'w')
>   file.close()
>   except:

If you dont want the vigilantes out in their squadrons please dont do it that 
way.

More seriously you can do what you like but dont teach beginners to use bare 
excepts.

Do
 except IOError  # I think... else whatever is the error you want to trap

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


Re: [beginner] What's wrong?

2016-04-03 Thread Rustom Mody
On Sunday, April 3, 2016 at 8:58:59 PM UTC+5:30, Dan Sommers wrote:
> On Sun, 03 Apr 2016 07:30:47 -0700, Rustom Mody wrote:
> 
> > So here are some examples to illustrate what I am saying:
> 
> [A vs a, A vs A, flag vs flag, etc.]

> I understand that in some use cases, flag and flag represent the same
> English word, but please don't extend that to identifiers in my
> software.

I wonder once again if you are getting my point opposite to the one I am making.
With ASCII there were problems like O vs 0 -- niggling but small.

With Unicode its a gigantic pandora box.
Python by allowing unicode identifiers without restraint has made grief for
unsuspecting programmers.

That is why my original suggestion that there should have been alongside this
'brave new world', a pragma wherein a programmer can EXPLICITLY declare
#language Greek
Then he is knowingly opting into possible clashes between A and Α
But not between A and А.

[And if you think the above is a philosophical disquisition on Aristotle's
law of identity: "A is A" you just proved my point that unconstrained Unicode
identifiers is a mess]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [beginner] What's wrong?

2016-04-03 Thread Rustom Mody
On Sunday, April 3, 2016 at 8:58:59 PM UTC+5:30, Dan Sommers wrote:
> Yes, it's marginally annoying, and a security hole waiting to happen,
> that A and A often look very much alike.


"A security hole waiting to happen" = "Marginally annoying"

Frankly I find this juxtaposition alarming

Personal note: I once was idiot enough to have root with password root123
and transferring some files to a friend ... over ssh...
Lost my entire installation in a matter of minutes
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [beginner] What's wrong?

2016-04-03 Thread Larry Martell
On Sun, Apr 3, 2016 at 11:46 AM, Rustom Mody  wrote:
> Personal note: I once was idiot enough to have root with password root123

I changed my password to "incorrect," so whenever I forget it the
computer will say, "Your password is incorrect."
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [beginner] What's wrong?

2016-04-03 Thread Chris Angelico
On Mon, Apr 4, 2016 at 1:46 AM, Rustom Mody  wrote:
> On Sunday, April 3, 2016 at 8:58:59 PM UTC+5:30, Dan Sommers wrote:
>> Yes, it's marginally annoying, and a security hole waiting to happen,
>> that A and A often look very much alike.
>
>
> "A security hole waiting to happen" = "Marginally annoying"
>
> Frankly I find this juxtaposition alarming
>
> Personal note: I once was idiot enough to have root with password root123
> and transferring some files to a friend ... over ssh...
> Lost my entire installation in a matter of minutes

Exactly why did you have root ssh access with a password?

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


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread BartC

On 03/04/2016 16:25, Rustom Mody wrote:

On Sunday, April 3, 2016 at 8:41:49 PM UTC+5:30, BartC wrote:



You can create the path manually outside of Python. Or look up the docs
to find out how to do that. A quick google suggested using os.makedirs
(to create multiple nested paths at the same time).



try:
os.stat(path)
except:
os.makedirs(path)

print (name)

try:
file=open(name,'w')
file.close()
except:


If you dont want the vigilantes out in their squadrons please dont do it that 
way.

More seriously you can do what you like but dont teach beginners to use bare 
excepts.


They're not mine (the first is from the first google hit, the second is 
the OP's); if it was my choice I wouldn't use exceptions at all.


But the primary issue here is that file not being created. Once the code 
works, it can be tweaked later and, if the path still needs creating 
from the code, there are doubtless better ways of doing it, with or 
without exceptions.


At the minute we don't even know if this was the problem.

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


Re: [beginner] What's wrong?

2016-04-03 Thread Dan Sommers
On Sun, 03 Apr 2016 08:46:59 -0700, Rustom Mody wrote:

> On Sunday, April 3, 2016 at 8:58:59 PM UTC+5:30, Dan Sommers wrote:
>> Yes, it's marginally annoying, and a security hole waiting to happen,
>> that A and A often look very much alike.
> 
> "A security hole waiting to happen" = "Marginally annoying"
> 
> Frankly I find this juxtaposition alarming

Sorry about that.

I didn't mean to equate the two.  I meant to point out that the fact
that A and A look alike can be one, or both, of those things.  Perhaps I
should have used "or" instead of "and."
-- 
https://mail.python.org/mailman/listinfo/python-list


i cant seem to figure out the error

2016-04-03 Thread anthony uwaifo
hi everyone,

please i need help with this assignment. I have written a code and i still
get an error. please help me debug my code.

instructions:

   - Create a constructor that takes in an integer and assigns this to a
   `balance` property.
   - Create a method called `deposit` that takes in cash deposit amount and
   updates the balance accordingly.
   - Create a method called `withdraw` that takes in cash withdrawal amount
   and updates the balance accordingly. if amount is greater than balance
   return `"invalid transaction"`
   - Create a subclass MinimumBalanceAccount of the BankAccount class


My code:

class BankAccount(object):
  def __init__(self, balance):
self.balance = balance


  def deposit(self, amount):
self.amount=amount
self.balance += amount
return self.balance


  def withdraw(self, amount):
self.amount=amount
if(amount > self.balance):
  return ("Amount greater than available balance.")
else:
  self.balance -= amount
return self.balance



class MinimumBalanceAccount(BankAccount):
  def __init__(self, minimum_balance):
BankAccount.__init__(self)
self.minimum_balance = minimum_balance

act = BankAccount(5)
act.deposit(400)
act.withdraw(200)
print act.balance


error message:

THERE IS AN ERROR/BUG IN YOUR CODE*Results: *
{"finished": true, "success": [{"fullName": "test_balance",
"passedSpecNumber": 1}, {"fullName": "test_deposit",
"passedSpecNumber": 2}, {"fullName": "test_sub_class",
"passedSpecNumber": 3}, {"fullName": "test_withdraw",
"passedSpecNumber": 4}], "passed": false, "started": true, "failures":
[{"failedSpecNumber": 1, "fullName": "test_invalid_operation",
"failedExpectations": [{"message": "Failure in line 23, in
test_invalid_operation\n
self.assertEqual(self.my_account.withdraw(1000), \"invalid
transaction\", msg='Invalid transaction')\nAssertionError: Invalid
transaction\n"}]}], "specs": {"count": 5, "pendingCount": 0, "time":
"0.79"}}
205
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [beginner] What's wrong?

2016-04-03 Thread Michael Okuntsov

03.04.2016 20:52, Rustom Mody пишет:


To really localize python one would have to
1. Localize the keywords
2. Localize all module names
3. Localize all the help strings
4. Localize the entire stuff up at https://docs.python.org/3/
5. ...

That is probably one or two orders of magnitude more work than
localizing gimp or Word

So if this is the full goal how far does
"You can now spell (or misspell) your python identifiers in any language of your 
choice"
go towards that goal?



As an OP, can I participate in the discussion? Here in Russia we have a 
monstrous bookkeeping system called 1C-Predpriyatiye that is used by 
almost all firms and organizations, from kiosks to huge factories. This 
system has a Basic-like language with keywords, module names etc. 
localized in Russian language, but it has also English, German, and 
Ukrainian localizations. I don't want to say that common programming 
languages should be like this, but here we have an example that it can 
be done.

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


Re: Strange range

2016-04-03 Thread Ethan Furman

On 04/02/2016 11:58 PM, Marko Rauhamaa wrote:

Stephen Hansen :


On Sat, Apr 2, 2016, at 02:40 PM, Marko Rauhamaa wrote:

That's why I was looking for counterexamples in the standard library


This entire bent of an argument seems flawed to me.

The standard library has never been a beacon for best practices or
idiomatic uses of Python.


It's an obvious corpus of Python code not written by me that's readily
available on my computer. An argument was made that range() has varied
uses. I was trying to find those varied uses.


Which is fine, but failing to find them is insignificant.



Most code exists outside the stdlib.


Which should then make it easy for you to point out the kinds of
counterexamples I was looking for.


I'm pretty sure that 99+% of the non-stdlib code out there is also 
completely inaccessible (or at least inconveniently accessible) to 
Stephen as well.


Besides which, the amount of extra effort someone else is willing to go 
to to prove something is directly related to the interestingness of the 
topic -- and the various uses of range() isn't that interesting (it 
would be more interesting if a PEP was on the line...) .


--
~Ethan~

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


Re: [beginner] What's wrong?

2016-04-03 Thread Chris Angelico
On Mon, Apr 4, 2016 at 2:24 AM, Michael Okuntsov
 wrote:
> As an OP, can I participate in the discussion? Here in Russia we have a
> monstrous bookkeeping system called 1C-Predpriyatiye that is used by almost
> all firms and organizations, from kiosks to huge factories. This system has
> a Basic-like language with keywords, module names etc. localized in Russian
> language, but it has also English, German, and Ukrainian localizations. I
> don't want to say that common programming languages should be like this, but
> here we have an example that it can be done.

Absolutely you can participate! And thank you. That's exactly the sort
of thing I'm talking about; you should be able to script that in
Russian if your business is primarily Russian.

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


Re: [beginner] What's wrong?

2016-04-03 Thread Dan Sommers
On Sun, 03 Apr 2016 08:39:02 -0700, Rustom Mody wrote:

> On Sunday, April 3, 2016 at 8:58:59 PM UTC+5:30, Dan Sommers wrote:
>> On Sun, 03 Apr 2016 07:30:47 -0700, Rustom Mody wrote:
>> 
>> > So here are some examples to illustrate what I am saying:
>> 
>> [A vs a, A vs A, flag vs flag, etc.]
> 
>> I understand that in some use cases, flag and flag represent the same
>> English word, but please don't extend that to identifiers in my
>> software.

> I wonder once again if you are getting my point opposite to the one I
> am making.  With ASCII there were problems like O vs 0 -- niggling but
> small.
> 
> With Unicode its a gigantic pandora box.  Python by allowing unicode
> identifiers without restraint has made grief for unsuspecting
> programmers.

What about the A vs a case, which comes up even with ASCII-only
characters?  If those are the same, then I, as a reader of Python code,
have to understand all the rules about ß (which I think have changed
over time), and potentially þ and others.

> That is why my original suggestion that there should have been alongside this
> 'brave new world', a pragma wherein a programmer can EXPLICITLY declare
> #language Greek
> Then he is knowingly opting into possible clashes between A and Α
> But not between A and А.

If I declared #language Greek, then I'd expect an identifier like A to
be rejected by the compiler.  That said, I don't know if that sort of
distinction is as clear cut in every language supported by Unicode.

And just to cause trouble (because that's the way I feel today), can I
declare

#γλώσσα Ελληνική

;-)

> [And if you think the above is a philosophical disquisition on
> Aristotle's law of identity: "A is A" you just proved my point that
> unconstrained Unicode identifiers is a mess]

Can we take a "we're all adults here" approach?  For the same reason
that adults don't use identifiers like xl0, x10, xlO, and xl0 anywhere
near each other, shouldn't we also not use A and A anywhere near each
other?  I certainly don't want the language itself to [try to] reject
x10 and xIO because they look too much alike in many fonts.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [beginner] What's wrong?

2016-04-03 Thread Chris Angelico
On Mon, Apr 4, 2016 at 2:22 AM, Dan Sommers  wrote:
> What about the A vs a case, which comes up even with ASCII-only
> characters?  If those are the same, then I, as a reader of Python code,
> have to understand all the rules about ß (which I think have changed
> over time), and potentially þ and others.

And Iİıi, and Σσς, and (if you want completeness) ſ too. And various
other case conversion rules. It's not possible to case-fold perfectly
without knowing what language something is.

This, coupled with the extremely useful case distinction between
"Classes" and "instances", means I'm very much glad Python is case
sensitive. "base = Base()" is perfectly legal and meaningful, no
matter what language you translate those words into (well, as long as
it's bicameral - otherwise you need to adorn one of them somehow, but
you'd have to anyway).

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


Re: [beginner] What's wrong?

2016-04-03 Thread Rustom Mody
On Sunday, April 3, 2016 at 9:30:40 PM UTC+5:30, Chris Angelico wrote:
> Exactly why did you have root ssh access with a password?

Umm... Dont exactly remember.
Probably it was not strictly necessary.
Combination of carelessness, stupidity, hurry

Brings me to...

On Sunday, April 3, 2016 at 9:41:11 PM UTC+5:30, Dan Sommers wrote:
> On Sun, 03 Apr 2016 08:46:59 -0700, Rustom Mody wrote:
> 
> > On Sunday, April 3, 2016 at 8:58:59 PM UTC+5:30, Dan Sommers wrote:
> >> Yes, it's marginally annoying, and a security hole waiting to happen,
> >> that A and A often look very much alike.
> > 
> > "A security hole waiting to happen" = "Marginally annoying"
> > 
> > Frankly I find this juxtaposition alarming
> 
> Sorry about that.
> 
> I didn't mean to equate the two.  I meant to point out that the fact
> that A and A look alike can be one, or both, of those things.  Perhaps I
> should have used "or" instead of "and."

Chill! No offence.

Just that when you have the above ingredients (carelessness, stupidity, 
hurry) multiplied by a GHz clock, it makes for spicy security
incidents(!).

I just meant to say that "Just a lil security incident" is not a helpful 
attitude to foster
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [beginner] What's wrong?

2016-04-03 Thread Rustom Mody
On Sunday, April 3, 2016 at 9:56:24 PM UTC+5:30, Dan Sommers wrote:
> On Sun, 03 Apr 2016 08:39:02 -0700, Rustom Mody wrote:
> 
> > On Sunday, April 3, 2016 at 8:58:59 PM UTC+5:30, Dan Sommers wrote:
> >> On Sun, 03 Apr 2016 07:30:47 -0700, Rustom Mody wrote:
> >> 
> >> > So here are some examples to illustrate what I am saying:
> >> 
> >> [A vs a, A vs A, flag vs flag, etc.]
> > 
> >> I understand that in some use cases, flag and flag represent the same
> >> English word, but please don't extend that to identifiers in my
> >> software.
> 
> > I wonder once again if you are getting my point opposite to the one I
> > am making.  With ASCII there were problems like O vs 0 -- niggling but
> > small.
> > 
> > With Unicode its a gigantic pandora box.  Python by allowing unicode
> > identifiers without restraint has made grief for unsuspecting
> > programmers.
> 
> What about the A vs a case, which comes up even with ASCII-only
> characters?  If those are the same, then I, as a reader of Python code,
> have to understand all the rules about ß (which I think have changed
> over time), and potentially þ and others.

Dont get your point.
If you know German then these rules should be clear enough to you
If not youve probably got bigger problems reading that code anyway

As illustration, here is Marko's code few posts back:

for oppilas in luokka:
if oppilas.hylätty():
oppilas.ilmoita(oppilas.koetulokset) 

Does it make sense to you?

> 
> > That is why my original suggestion that there should have been alongside 
> > this
> > 'brave new world', a pragma wherein a programmer can EXPLICITLY declare
> > #language Greek
> > Then he is knowingly opting into possible clashes between A and Α
> > But not between A and А.
> 
> If I declared #language Greek, then I'd expect an identifier like A to
> be rejected by the compiler.  That said, I don't know if that sort of
> distinction is as clear cut in every language supported by Unicode.
> 
> And just to cause trouble (because that's the way I feel today), can I
> declare
> 
> #γλώσσα Ελληνική
> 
> ;-)
> 
> > [And if you think the above is a philosophical disquisition on
> > Aristotle's law of identity: "A is A" you just proved my point that
> > unconstrained Unicode identifiers is a mess]
> 
> Can we take a "we're all adults here" approach?

Who's the 'we' we are talking about?

> For the same reason
> that adults don't use identifiers like xl0, x10, xlO, and xl0 anywhere
> near each other, shouldn't we also not use A and A anywhere near each
> other?  I certainly don't want the language itself to [try to] reject
> x10 and xIO because they look too much alike in many fonts.

When Kernighan and Ritchie wrote C there was no problem with gets.
Then suddenly, decades later the problem exploded.

What happened?

Here's an analysis:
Security means two almost completely unrelated concepts
- protection against shooting oneself in the foot (remember the 'protected' 
   keyword of C++ ?)
- protection against intelligent, capable, motivated criminals
Lets call them security-s (against stupidity) and security-c (against criminals)

Security-c didnt figure because computers were anyway physically secured and 
there was no much internet to speak of.
gets was provided exactly on your principle of 'consenting-adults' -- if you
use it you know what you are using.

Then suddenly computers became net-facing and their servers could be written by
'consenting' (to whom?) adults using gets.

Voila -- Security has just become a lucrative profession!

I believe python's situation of laissez-faire unicode is similarly 
trouble-inviting.

While I personally dont know enough about security to be able to demonstrate a
full sequence of events, here's a little fun I had with Chris:

https://mail.python.org/pipermail/python-list/2014-May/672413.html

Do you not think this could be tailored into something more sinister and
dangerous?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: i cant seem to figure out the error

2016-04-03 Thread Jason Friedman
>
>- Create a method called `withdraw` that takes in cash withdrawal amount
>and updates the balance accordingly. if amount is greater than balance
>return `"invalid transaction"`
>
>   def withdraw(self, amount):
> self.amount=amount
> if(amount > self.balance):
>   return ("Amount greater than available balance.")
> else:
>   self.balance -= amount
> return self.balance
>

The instructions say to "return 'invalid transaction'" but I expect they
really want that error printed to STDERR (typically your screen) rather
than literally returned.  Try this:

  def withdraw(self, amount):
self.amount=amount
if(amount > self.balance):
  print "Amount greater than available balance, no funds withdrawn."
else:
  self.balance -= amount
return self.balance
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [beginner] What's wrong?

2016-04-03 Thread Chris Angelico
On Mon, Apr 4, 2016 at 3:18 AM, Rustom Mody  wrote:
> While I personally dont know enough about security to be able to demonstrate a
> full sequence of events, here's a little fun I had with Chris:
>
> https://mail.python.org/pipermail/python-list/2014-May/672413.html
>
> Do you not think this could be tailored into something more sinister and
> dangerous?

I honestly don't know what you're proving there. You didn't import a
file called "1.py"; you just created a file with a non-ASCII name and
used a non-ASCII identifier to import it. In other words, you did
exactly what Unicode should allow: names in any language.

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


Re: i cant seem to figure out the error

2016-04-03 Thread Jason Friedman
>   def deposit(self, amount):
> self.amount=amount
> self.balance += amount
> return self.balance
>
>
>   def withdraw(self, amount):
> self.amount=amount
> if(amount > self.balance):
>   return ("Amount greater than available balance.")
> else:
>   self.balance -= amount
> return self.balance

Also, this line is not needed in the deposit and withdraw methods:

self.amount=amount
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: i cant seem to figure out the error

2016-04-03 Thread MRAB

On 2016-04-03 16:06, anthony uwaifo wrote:

hi everyone,

please i need help with this assignment. I have written a code and i still
get an error. please help me debug my code.

instructions:

- Create a constructor that takes in an integer and assigns this to a
`balance` property.
- Create a method called `deposit` that takes in cash deposit amount and
updates the balance accordingly.
- Create a method called `withdraw` that takes in cash withdrawal amount
and updates the balance accordingly. if amount is greater than balance
return `"invalid transaction"`
- Create a subclass MinimumBalanceAccount of the BankAccount class


My code:

class BankAccount(object):
   def __init__(self, balance):
 self.balance = balance


   def deposit(self, amount):
 self.amount=amount
 self.balance += amount
 return self.balance


   def withdraw(self, amount):
 self.amount=amount
 if(amount > self.balance):
   return ("Amount greater than available balance.")
 else:
   self.balance -= amount
 return self.balance



class MinimumBalanceAccount(BankAccount):
   def __init__(self, minimum_balance):
 BankAccount.__init__(self)
 self.minimum_balance = minimum_balance

act = BankAccount(5)
act.deposit(400)
act.withdraw(200)
print act.balance


error message:

THERE IS AN ERROR/BUG IN YOUR CODE*Results: *
{"finished": true, "success": [{"fullName": "test_balance",
"passedSpecNumber": 1}, {"fullName": "test_deposit",
"passedSpecNumber": 2}, {"fullName": "test_sub_class",
"passedSpecNumber": 3}, {"fullName": "test_withdraw",
"passedSpecNumber": 4}], "passed": false, "started": true, "failures":
[{"failedSpecNumber": 1, "fullName": "test_invalid_operation",
"failedExpectations": [{"message": "Failure in line 23, in
test_invalid_operation\n
self.assertEqual(self.my_account.withdraw(1000), \"invalid
transaction\", msg='Invalid transaction')\nAssertionError: Invalid
transaction\n"}]}], "specs": {"count": 5, "pendingCount": 0, "time":
"0.79"}}
205

What do the instructions say that `withdraw` should return if the amount 
is greater than the balance?


What would your code return in such a case?

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


Re: i cant seem to figure out the error

2016-04-03 Thread Peter Pearson
On Sun, 3 Apr 2016 16:06:58 +0100, anthony uwaifo wrote:
[snip]
>
> class BankAccount(object):
>   def __init__(self, balance):
> self.balance = balance
>
>
>   def deposit(self, amount):
> self.amount=amount
> self.balance += amount
> return self.balance
>
>
>   def withdraw(self, amount):
> self.amount=amount
> if(amount > self.balance):
>   return ("Amount greater than available balance.")
> else:
>   self.balance -= amount
> return self.balance
>
>
>
> class MinimumBalanceAccount(BankAccount):
>   def __init__(self, minimum_balance):
> BankAccount.__init__(self)
> self.minimum_balance = minimum_balance
>
> act = BankAccount(5)
> act.deposit(400)
> act.withdraw(200)
> print act.balance

There is an indentation error following the "else:" line.  After
I fixed that, the program runs and prints "205" (under Python 2.7.3).

-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: i cant seem to figure out the error

2016-04-03 Thread MRAB

On 2016-04-03 18:34, Jason Friedman wrote:


   - Create a method called `withdraw` that takes in cash withdrawal amount
   and updates the balance accordingly. if amount is greater than balance
   return `"invalid transaction"`

  def withdraw(self, amount):
self.amount=amount
if(amount > self.balance):
  return ("Amount greater than available balance.")
else:
  self.balance -= amount
return self.balance



The instructions say to "return 'invalid transaction'" but I expect they
really want that error printed to STDERR (typically your screen) rather
than literally returned.  Try this:

   def withdraw(self, amount):
 self.amount=amount
 if(amount > self.balance):
   print "Amount greater than available balance, no funds withdrawn."
 else:
   self.balance -= amount
 return self.balance


The instructions say "return", not "print" and the report contains:

self.assertEqual(self.my_account.withdraw(1000), "invalid transaction", 
msg='Invalid transaction')


so it _is_ checking the returned result of 'withdraw'.

Not Pythonic (neither is printing to stderr! :-)), but that's something 
that can be worked on later.


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


Re: [beginner] What's wrong?

2016-04-03 Thread Dan Sommers
On Sun, 03 Apr 2016 10:18:45 -0700, Rustom Mody wrote:

> On Sunday, April 3, 2016 at 9:56:24 PM UTC+5:30, Dan Sommers wrote:
>> On Sun, 03 Apr 2016 08:39:02 -0700, Rustom Mody wrote:
>> 
>> > On Sunday, April 3, 2016 at 8:58:59 PM UTC+5:30, Dan Sommers wrote:
>> >> On Sun, 03 Apr 2016 07:30:47 -0700, Rustom Mody wrote:
>> >> 
>> >> > So here are some examples to illustrate what I am saying:
>> >> 
>> >> [A vs a, A vs A, flag vs flag, etc.]
>> > 
>> >> I understand that in some use cases, flag and flag represent the same
>> >> English word, but please don't extend that to identifiers in my
>> >> software.
>> 
>> > I wonder once again if you are getting my point opposite to the one I
>> > am making.  With ASCII there were problems like O vs 0 -- niggling but
>> > small.
>> > 
>> > With Unicode its a gigantic pandora box.  Python by allowing unicode
>> > identifiers without restraint has made grief for unsuspecting
>> > programmers.
>> 
>> What about the A vs a case, which comes up even with ASCII-only
>> characters?  If those are the same, then I, as a reader of Python code,
>> have to understand all the rules about ß (which I think have changed
>> over time), and potentially þ and others.
> 
> Dont get your point.
> If you know German then these rules should be clear enough to you
> If not youve probably got bigger problems reading that code anyway

My point is that case sensitivity is good.  I was disagreeing with your
point about scheme getting A vs a "right" and Python and C and Unix
getting it "wrong."

My larger point, and my experience, is that case sensitivity is easier
for to handle than case insensitivity.  Most of the time, the same
letter's capital and small renditions look different from each other (A
vs a, Q vs q, and even Þ and þ is no worse than O and o), and there are
no context sensitive conversion rules to worry about.

> As illustration, here is Marko's code few posts back:
> 
> for oppilas in luokka:
> if oppilas.hylätty():
> oppilas.ilmoita(oppilas.koetulokset) 
> 
> Does it make sense to you?

It makes enough sense to recognize the idiom:  for each item in a
collection that satisfies a predicate, call a method on the item.

My point here is that while the identifiers themselves can be enormously
helpful to someone seeing a block of code for the first time or
maintaining it five years later, it's just as important to recognize
quickly that one identifier is not the same as another one, or that a
particular identifier only appears once or only in certain syntactical
constructs.

If the above code were written a little differently, we'd be having a
completely different discussion:

for list in object:
if list.clear():
list.pop(list.append)

>> Can we take a "we're all adults here" approach?
> 
> Who's the 'we' we are talking about?

The community, who has accepted Python as a case-sensitive language and
knows better than to use identifiers that look too much alike or are
otherwise deliberatly mis-leading.

>> For the same reason
>> that adults don't use identifiers like xl0, x10, xlO, and xl0 anywhere
>> near each other, shouldn't we also not use A and A anywhere near each
>> other?  I certainly don't want the language itself to [try to] reject
>> x10 and xIO because they look too much alike in many fonts.
> 
> When Kernighan and Ritchie wrote C there was no problem with gets.
> Then suddenly, decades later the problem exploded.

When Kernighan and Ritchie wrote C there *was* a problem with gets.

> What happened?

The problem was no longer isolated to taking down one Unix process or a
single machine, or discovering passwords on that one machine.

> Here's an analysis:
> Security means two almost completely unrelated concepts
> - protection against shooting oneself in the foot (remember the 'protected' 
>keyword of C++ ?)
> - protection against intelligent, capable, motivated criminals
> Lets call them security-s (against stupidity) and security-c (against 
> criminals)
> 
> Security-c didnt figure because computers were anyway physically secured and 
> there was no much internet to speak of.
> gets was provided exactly on your principle of 'consenting-adults' -- if you
> use it you know what you are using.
> 
> Then suddenly computers became net-facing and their servers could be
> written by 'consenting' (to whom?) adults using gets.
> 
> Voila -- Security has just become a lucrative profession!

I can't prevent insecure web servers, or unknowing users.  Allowing or
disallowing A and A and А to coexist in the source code doesn't matter.

> I believe python's situation of laissez-faire unicode is similarly
> trouble-inviting.

I'm not sure I agree, but I didn't timing attacks on cryptographic
algorithms or devices reading passwords from air-gapped computers
coming, either.

I do know that complexity is also a source of bugs and security risks.
Allowing or disallowing certain unicode code points in identifiers, and
declaring that identifiers c

Re: Sorting a list

2016-04-03 Thread DFS

On 4/3/2016 2:30 PM, DFS wrote:

cntText = 60
cntBool = 20
cntNbrs = 30
cntDate = 20
cntBins = 20

strText = "  text: "
strBool = "  boolean:  "
strNbrs = "  numeric:  "
strDate = "  date-time:"
strBins = "  binary:   "

colCounts = [(cntText,strText) , (cntBool,strBool), (cntNbrs,strNbrs) ,
(cntDate,strDate) , (cntBins,strBins)]

# sort by alpha, then by column type count descending
colCounts.sort(key=lambda x: x[1])
colCounts.sort(key=lambda x: x[0], reverse=True)
for key in colCounts: print key[1], key[0]]

-

Output (which is exactly what I want):

   text:  60
   numeric:   30
   binary:20
   boolean:   20
   date-time: 20

-


But, is there a 1-line way to sort and print?


Meant to include this example:

print {i:os.strerror(i) for i in sorted(errno.errorcode)}




Thanks!





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


Sorting a list

2016-04-03 Thread DFS

cntText = 60
cntBool = 20
cntNbrs = 30
cntDate = 20
cntBins = 20

strText = "  text: "
strBool = "  boolean:  "
strNbrs = "  numeric:  "
strDate = "  date-time:"
strBins = "  binary:   "

colCounts = [(cntText,strText) , (cntBool,strBool), (cntNbrs,strNbrs) , 
(cntDate,strDate) , (cntBins,strBins)]


# sort by alpha, then by column type count descending
colCounts.sort(key=lambda x: x[1])
colCounts.sort(key=lambda x: x[0], reverse=True)
for key in colCounts: print key[1], key[0]]

-

Output (which is exactly what I want):

  text:  60
  numeric:   30
  binary:20
  boolean:   20
  date-time: 20

-


But, is there a 1-line way to sort and print?


Thanks!



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


Re: [beginner] What's wrong?

2016-04-03 Thread Dan Sommers
On Sun, 03 Apr 2016 09:49:03 -0700, Rustom Mody wrote:

> On Sunday, April 3, 2016 at 9:41:11 PM UTC+5:30, Dan Sommers wrote:
>> On Sun, 03 Apr 2016 08:46:59 -0700, Rustom Mody wrote:
>> 
>> > On Sunday, April 3, 2016 at 8:58:59 PM UTC+5:30, Dan Sommers wrote:
>> >> Yes, it's marginally annoying, and a security hole waiting to happen,
>> >> that A and A often look very much alike.
>> > 
>> > "A security hole waiting to happen" = "Marginally annoying"
>> > 
>> > Frankly I find this juxtaposition alarming
>> 
>> Sorry about that.
>> 
>> I didn't mean to equate the two.  I meant to point out that the fact
>> that A and A look alike can be one, or both, of those things.  Perhaps I
>> should have used "or" instead of "and."
> 
> Chill! No offence.

I'm chilled.  :-)

No offense taken.  I am arguably overly sensitive to putting forth an
argument that isn't clear and concise (because I've also been known to
derail the proceedings until I can get my head around someone else's
argument).

> Just that when you have the above ingredients (carelessness,
> stupidity, hurry) multiplied by a GHz clock, it makes for spicy
> security incidents(!).  I just meant to say that "Just a lil security
> incident" is not a helpful attitude to foster

On this we agree.  :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


PyQt4

2016-04-03 Thread Muhammad Ali

Hi,

How can we confirm that either  PyQt4 is already installed on LInux machine or 
not?

Please suggest commands to confirm the already existence of  PyQt4 in the 
machine.

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


Plot/Graph

2016-04-03 Thread Muhammad Ali

Hi,

Could anybody tell me that how can I plot graphs by matplotlib and get 
expertise in a short time? I have to plot 2D plots just like origin software. 

Secondly, how could we draw some horizontal reference line at zero when the 
vertical scale is from -3 to 3? 

Looking for your posts, please.

Thank you.

p.s: Is there any short and to the point text book/manual/pdf to learn 2D 
plotting with matplotlib?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyQt4

2016-04-03 Thread Michael Torrie
On 04/03/2016 12:57 PM, Muhammad Ali wrote:
> 
> Hi,
> 
> How can we confirm that either  PyQt4 is already installed on LInux machine 
> or not?
> 
> Please suggest commands to confirm the already existence of  PyQt4 in the 
> machine.

Ideally you make a distribution-specific package of the binary in a .deb
on Debian or an RPM on other distros, and specify that it depends on the
package that provides PyQt4.  That way when it's installed, modern
package managers will automatically install the dependencies.

Alternatively you can use try and except in your python code to attempt
to import something from PyQt4 and see if it fails or not.  This
technique is also used to make your code work either PyQt4 or PySide,
depending on which the user has installed.

try:
from PySide import QtGui
except ImportError:
from PyQt4 import QtGui

If neither are installed, this little example will end with an ImportError.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sorting a list

2016-04-03 Thread Peter Otten
DFS wrote:

> cntText = 60
> cntBool = 20
> cntNbrs = 30
> cntDate = 20
> cntBins = 20
> 
> strText = "  text: "
> strBool = "  boolean:  "
> strNbrs = "  numeric:  "
> strDate = "  date-time:"
> strBins = "  binary:   "
> 
> colCounts = [(cntText,strText) , (cntBool,strBool), (cntNbrs,strNbrs) ,
> (cntDate,strDate) , (cntBins,strBins)]
> 
> # sort by alpha, then by column type count descending
> colCounts.sort(key=lambda x: x[1])
> colCounts.sort(key=lambda x: x[0], reverse=True)
> for key in colCounts: print key[1], key[0]]
> 
> -
> 
> Output (which is exactly what I want):
> 
>text:  60
>numeric:   30
>binary:20
>boolean:   20
>date-time: 20
> 
> -
> 
> 
> But, is there a 1-line way to sort and print?

Yes, but I would not recommend it. You can replace the sort() method 
invocations with nested calls of sorted() and instead of

for item in items:
print convert_to_str(item)

use

print "\n".join(convert_to_str(item) for item in items)

Putting it together:

>>> from operator import itemgetter as get
>>> print "\n".join("{1} {0}".format(*p) for p in sorted(
... sorted(colCounts, key=get(1)), key=get(0), reverse=True))
  text:  60
  numeric:   30
  binary:20
  boolean:   20
  date-time: 20

You could also cheat and use

lambda v: (-v[0], v[1])

and a single sorted().

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


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread Loop.IO
On Sunday, April 3, 2016 at 4:11:49 PM UTC+1, BartC wrote:
> On 03/04/2016 15:41, Loop.IO wrote:
> > On Sunday, April 3, 2016 at 1:12:23 AM UTC+1, BartC wrote:
> >> On 02/04/2016 23:31, Loop.IO wrote:
> >>
> >>> Oh i see, so the code prompts for a name.. so i'm more lost than i 
> >>> thought, what do I need to change to make it just create the file with 
> >>> the chosen name Launch2.bat without the prompt?
> >>
> >> If you don't want the user to enter anything, then I explained how
> >> before, just use:
> >>
> >>name='C:\\Documents\\PythonCoding\\launch2.bat'
> >>
> >> if that's the file name you need.
> >>
> >> --
> >> Bartc
> >
> > Hi Bartc, i tried that, didn't work
> 
> You mean it gave an error when you tried to create that file?
> 
> Does that path already exist on your machine? If not then trying to 
> create a file in a non-existent path won't work.
> 
> You can create the path manually outside of Python. Or look up the docs 
> to find out how to do that. A quick google suggested using os.makedirs 
> (to create multiple nested paths at the same time).
> 
> The following code worked on my machine:
> 
> import sys
> import os
> 
> def create():
>   print("creating new file")
> 
>   path="c:/Documents/PythonCoding/"
>   name=path+"launch2.bat"
> 
>   try:
>   os.stat(path)
>   except:
>   os.makedirs(path)
> 
>   print (name)
> 
>   try:
>   file=open(name,'w')
>   file.close()
>   except:
>   print("error occured")
>   sys.exit(0)
> 
> create()
> 
> -- 
> Bartc

The issue is that it hangs, there is no error. its like it pauses until i press 
enter, ill try what you've posted one moment
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread Loop.IO
On Sunday, April 3, 2016 at 8:32:06 PM UTC+1, Loop.IO wrote:
> On Sunday, April 3, 2016 at 4:11:49 PM UTC+1, BartC wrote:
> > On 03/04/2016 15:41, Loop.IO wrote:
> > > On Sunday, April 3, 2016 at 1:12:23 AM UTC+1, BartC wrote:
> > >> On 02/04/2016 23:31, Loop.IO wrote:
> > >>
> > >>> Oh i see, so the code prompts for a name.. so i'm more lost than i 
> > >>> thought, what do I need to change to make it just create the file with 
> > >>> the chosen name Launch2.bat without the prompt?
> > >>
> > >> If you don't want the user to enter anything, then I explained how
> > >> before, just use:
> > >>
> > >>name='C:\\Documents\\PythonCoding\\launch2.bat'
> > >>
> > >> if that's the file name you need.
> > >>
> > >> --
> > >> Bartc
> > >
> > > Hi Bartc, i tried that, didn't work
> > 
> > You mean it gave an error when you tried to create that file?
> > 
> > Does that path already exist on your machine? If not then trying to 
> > create a file in a non-existent path won't work.
> > 
> > You can create the path manually outside of Python. Or look up the docs 
> > to find out how to do that. A quick google suggested using os.makedirs 
> > (to create multiple nested paths at the same time).
> > 
> > The following code worked on my machine:
> > 
> > import sys
> > import os
> > 
> > def create():
> > print("creating new file")
> > 
> > path="c:/Documents/PythonCoding/"
> > name=path+"launch2.bat"
> > 
> > try:
> > os.stat(path)
> > except:
> > os.makedirs(path)
> > 
> > print (name)
> > 
> > try:
> > file=open(name,'w')
> > file.close()
> > except:
> > print("error occured")
> > sys.exit(0)
> > 
> > create()
> > 
> > -- 
> > Bartc
> 
> The issue is that it hangs, there is no error. its like it pauses until i 
> press enter, ill try what you've posted one moment

Ok the Bartc code gives me an error.

What is it that makes the code hang with what I have, you said it was that it's 
prompting for a name for the file, so how do I bypass that and force it to 
create the file with the name I've provided?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyQt4

2016-04-03 Thread Muhammad Ali
On Sunday, April 3, 2016 at 12:15:06 PM UTC-7, Michael Torrie wrote:
> On 04/03/2016 12:57 PM, Muhammad Ali wrote:
> > 
> > Hi,
> > 
> > How can we confirm that either  PyQt4 is already installed on LInux machine 
> > or not?
> > 
> > Please suggest commands to confirm the already existence of  PyQt4 in the 
> > machine.
> 
> Ideally you make a distribution-specific package of the binary in a .deb
> on Debian or an RPM on other distros, and specify that it depends on the
> package that provides PyQt4.  That way when it's installed, modern
> package managers will automatically install the dependencies.
> 
> Alternatively you can use try and except in your python code to attempt
> to import something from PyQt4 and see if it fails or not.  This
> technique is also used to make your code work either PyQt4 or PySide,
> depending on which the user has installed.
> 
> try:
> from PySide import QtGui
> except ImportError:
> from PyQt4 import QtGui
> 
> If neither are installed, this little example will end with an ImportError.

Thank you for your suggestions. I tried both but it shows the following error:
IndentationError: expected an indented block

Actually, I have to plot some graphs by using matplotlib and PyQt4 at 
supercomputer.

Any other suggestion???
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread Erik

Hi Loop.IO,

On 03/04/16 15:41, Loop.IO wrote:

If you don't want the user to enter anything, then I explained how
before, just use:

   name='C:\\Documents\\PythonCoding\\launch2.bat'

if that's the file name you need.

--
Bartc


Hi Bartc, i tried that, didn't work


FYI, for the future.

Telling someone what _didn't_ happen is generally not very useful to 
them if you expect them to try to help further.


If you tell them what _did_ happen (be that an error message or a weird 
file created or a pain in your leg or whatever), then that is much more 
likely to be productive ;)


If you would like someone to diagnose your illness, you must explain 
your symptoms ...


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


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread Michael Selik
How do you know when you're done typing the name of the file?

It's hard to get tone right on the internet, so I'll clarify: this is not a
rhetorical question and I mean you, LoopIO, not a generic person.

On Sun, Apr 3, 2016, 8:40 PM Loop.IO  wrote:

> On Sunday, April 3, 2016 at 8:32:06 PM UTC+1, Loop.IO wrote:
> > On Sunday, April 3, 2016 at 4:11:49 PM UTC+1, BartC wrote:
> > > On 03/04/2016 15:41, Loop.IO wrote:
> > > > On Sunday, April 3, 2016 at 1:12:23 AM UTC+1, BartC wrote:
> > > >> On 02/04/2016 23:31, Loop.IO wrote:
> > > >>
> > > >>> Oh i see, so the code prompts for a name.. so i'm more lost than i
> thought, what do I need to change to make it just create the file with the
> chosen name Launch2.bat without the prompt?
> > > >>
> > > >> If you don't want the user to enter anything, then I explained how
> > > >> before, just use:
> > > >>
> > > >>name='C:\\Documents\\PythonCoding\\launch2.bat'
> > > >>
> > > >> if that's the file name you need.
> > > >>
> > > >> --
> > > >> Bartc
> > > >
> > > > Hi Bartc, i tried that, didn't work
> > >
> > > You mean it gave an error when you tried to create that file?
> > >
> > > Does that path already exist on your machine? If not then trying to
> > > create a file in a non-existent path won't work.
> > >
> > > You can create the path manually outside of Python. Or look up the docs
> > > to find out how to do that. A quick google suggested using os.makedirs
> > > (to create multiple nested paths at the same time).
> > >
> > > The following code worked on my machine:
> > >
> > > import sys
> > > import os
> > >
> > > def create():
> > > print("creating new file")
> > >
> > > path="c:/Documents/PythonCoding/"
> > > name=path+"launch2.bat"
> > >
> > > try:
> > > os.stat(path)
> > > except:
> > > os.makedirs(path)
> > >
> > > print (name)
> > >
> > > try:
> > > file=open(name,'w')
> > > file.close()
> > > except:
> > > print("error occured")
> > > sys.exit(0)
> > >
> > > create()
> > >
> > > --
> > > Bartc
> >
> > The issue is that it hangs, there is no error. its like it pauses until
> i press enter, ill try what you've posted one moment
>
> Ok the Bartc code gives me an error.
>
> What is it that makes the code hang with what I have, you said it was that
> it's prompting for a name for the file, so how do I bypass that and force
> it to create the file with the name I've provided?
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread Loop.IO
On Sunday, April 3, 2016 at 1:38:48 AM UTC+1, Mark Lawrence wrote:
> On 03/04/2016 01:12, BartC wrote:
> > On 02/04/2016 23:31, Loop.IO wrote:
> >
> >> Oh i see, so the code prompts for a name.. so i'm more lost than i
> >> thought, what do I need to change to make it just create the file with
> >> the chosen name Launch2.bat without the prompt?
> >
> > If you don't want the user to enter anything, then I explained how
> > before, just use:
> >
> >   name='C:\\Documents\\PythonCoding\\launch2.bat'
> >
> > if that's the file name you need.
> >
> 
> name = r'C:\Documents\PythonCoding\launch2.bat'
> 
> Alternatively you could just use a forward slash.
> 
> I'm not sure which is the most efficient, I'll leave that to others to test.
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

Hey Mark,

Sorry i totally missed your input, and guess what, it solved it !!!

Thanks man, it created the file and finished, what is different with r and 
raw_input
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread Loop.IO
On Sunday, April 3, 2016 at 8:49:28 PM UTC+1, Erik wrote:
> Hi Loop.IO,
> 
> On 03/04/16 15:41, Loop.IO wrote:
> >> If you don't want the user to enter anything, then I explained how
> >> before, just use:
> >>
> >>name='C:\\Documents\\PythonCoding\\launch2.bat'
> >>
> >> if that's the file name you need.
> >>
> >> --
> >> Bartc
> >
> > Hi Bartc, i tried that, didn't work
> 
> FYI, for the future.
> 
> Telling someone what _didn't_ happen is generally not very useful to 
> them if you expect them to try to help further.
> 
> If you tell them what _did_ happen (be that an error message or a weird 
> file created or a pain in your leg or whatever), then that is much more 
> likely to be productive ;)
> 
> If you would like someone to diagnose your illness, you must explain 
> your symptoms ...
> 
> E.

The original post said what did happen, the code runs and hangs on the create 
file, and once i press Enter it then finishes and creates the file, not sure 
how you missed that but thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sorting a list

2016-04-03 Thread DFS

On 4/3/2016 3:31 PM, Peter Otten wrote:

DFS wrote:


cntText = 60
cntBool = 20
cntNbrs = 30
cntDate = 20
cntBins = 20

strText = "  text: "
strBool = "  boolean:  "
strNbrs = "  numeric:  "
strDate = "  date-time:"
strBins = "  binary:   "

colCounts = [(cntText,strText) , (cntBool,strBool), (cntNbrs,strNbrs) ,
(cntDate,strDate) , (cntBins,strBins)]

# sort by alpha, then by column type count descending
colCounts.sort(key=lambda x: x[1])
colCounts.sort(key=lambda x: x[0], reverse=True)
for key in colCounts: print key[1], key[0]]

-

Output (which is exactly what I want):

text:  60
numeric:   30
binary:20
boolean:   20
date-time: 20

-


But, is there a 1-line way to sort and print?


Yes, but I would not recommend it. You can replace the sort() method
invocations with nested calls of sorted() and instead of

for item in items:
 print convert_to_str(item)

use

print "\n".join(convert_to_str(item) for item in items)

Putting it together:


from operator import itemgetter as get
print "\n".join("{1} {0}".format(*p) for p in sorted(

... sorted(colCounts, key=get(1)), key=get(0), reverse=True))


Kind of clunky looking.  Is that why don't you recommend it?





   text:  60
   numeric:   30
   binary:20
   boolean:   20
   date-time: 20

You could also cheat and use

lambda v: (-v[0], v[1])

and a single sorted().


That works well.  Why is it 'cheating'?


Thanks for the reply.


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


Re: i cant seem to figure out the error

2016-04-03 Thread Erik

Hi Anthony,

On 03/04/16 16:06, anthony uwaifo wrote:

please i need help with this assignment. I have written a code and i still
get an error. please help me debug my code.


We see this assignment come up a lot. The "tutor" list is a better place 
to go, but well done for at least attempting it and coming up with quite 
a good result.



- Create a method called `withdraw` that takes in cash withdrawal amount
and updates the balance accordingly. if amount is greater than balance
return `"invalid transaction"`


Read this carefully. Read it _literally_. What does your 'withdraw' 
method return?


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


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread Erik

On 03/04/16 20:54, Loop.IO wrote:

The original post said what did happen, the code runs and hangs on
the create file, and once i press Enter it then finishes and creates
the file, not sure how you missed that but thanks


Yes, I read your original post. That was days ago.

The comment I was replying to was you telling BartC that what he had
suggested "didn't work" (with no further information).

Please pay attention to the context of the email you are responding to.

E.


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


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread BartC

On 03/04/2016 20:36, Loop.IO wrote:

On Sunday, April 3, 2016 at 8:32:06 PM UTC+1, Loop.IO wrote:



The issue is that it hangs, there is no error. its like it pauses until i press 
enter, ill try what you've posted one momen




Ok the Bartc code gives me an error.


This is confusing! I know you said you fixed the problem now, but if it 
was waiting for the user to press enter, then you still had a raw_input 
or input() call in your code.


You need to get rid of that raw_input(). That was explained early on in 
the thread but perhaps you didn't grasp that you had to use:


  name = ''

in place of:

  name = raw_input()

and not as well as!

(And the 'r' in name = r'' isn't a different version of raw_input(), 
it's just a way of entering strings without having to type \\ when you 
need \.)


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


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread Loop.IO
On Sunday, April 3, 2016 at 9:15:22 PM UTC+1, Erik wrote:
> On 03/04/16 20:54, Loop.IO wrote:
> > The original post said what did happen, the code runs and hangs on
> > the create file, and once i press Enter it then finishes and creates
> > the file, not sure how you missed that but thanks
> 
> Yes, I read your original post. That was days ago.
> 
> The comment I was replying to was you telling BartC that what he had
> suggested "didn't work" (with no further information).
> 
> Please pay attention to the context of the email you are responding to.
> 
> E.

Erik

It was a syntax error. But sure, thanks.

The problem has been rectified, I used the r as suggested by Mark.

I've now been able to get the file created and write the code in the file, 
thanks for everyones replies.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyQt4

2016-04-03 Thread Vincent Vande Vyvre

Le 03/04/2016 21:36, Muhammad Ali a écrit :

On Sunday, April 3, 2016 at 12:15:06 PM UTC-7, Michael Torrie wrote:

On 04/03/2016 12:57 PM, Muhammad Ali wrote:

Hi,

How can we confirm that either  PyQt4 is already installed on LInux machine or 
not?

Please suggest commands to confirm the already existence of  PyQt4 in the 
machine.

Ideally you make a distribution-specific package of the binary in a .deb
on Debian or an RPM on other distros, and specify that it depends on the
package that provides PyQt4.  That way when it's installed, modern
package managers will automatically install the dependencies.

Alternatively you can use try and except in your python code to attempt
to import something from PyQt4 and see if it fails or not.  This
technique is also used to make your code work either PyQt4 or PySide,
depending on which the user has installed.

try:
 from PySide import QtGui
except ImportError:
 from PyQt4 import QtGui

If neither are installed, this little example will end with an ImportError.

Thank you for your suggestions. I tried both but it shows the following error:
IndentationError: expected an indented block

Actually, I have to plot some graphs by using matplotlib and PyQt4 at 
supercomputer.

Any other suggestion???


There's no IndentationError in the exemple provided by Michael.

Copy the code AS IT in a file and retry.

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


Re: Plot/Graph

2016-04-03 Thread Michael Selik
Indeed there is. Every example in the gallery shows the code to produce it.

http://matplotlib.org/gallery.html

On Sun, Apr 3, 2016, 8:05 PM Muhammad Ali 
wrote:

>
> Hi,
>
> Could anybody tell me that how can I plot graphs by matplotlib and get
> expertise in a short time? I have to plot 2D plots just like origin
> software.
>
> Secondly, how could we draw some horizontal reference line at zero when
> the vertical scale is from -3 to 3?
>
> Looking for your posts, please.
>
> Thank you.
>
> p.s: Is there any short and to the point text book/manual/pdf to learn 2D
> plotting with matplotlib?
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread Loop.IO
On Sunday, April 3, 2016 at 9:21:44 PM UTC+1, BartC wrote:
> On 03/04/2016 20:36, Loop.IO wrote:
> > On Sunday, April 3, 2016 at 8:32:06 PM UTC+1, Loop.IO wrote:
> 
> >> The issue is that it hangs, there is no error. its like it pauses until i 
> >> press enter, ill try what you've posted one momen
> 
> 
> > Ok the Bartc code gives me an error.
> 
> This is confusing! I know you said you fixed the problem now, but if it 
> was waiting for the user to press enter, then you still had a raw_input 
> or input() call in your code.
> 
> You need to get rid of that raw_input(). That was explained early on in 
> the thread but perhaps you didn't grasp that you had to use:
> 
>name = ''
> 
> in place of:
> 
>name = raw_input()
> 
> and not as well as!
> 
> (And the 'r' in name = r'' isn't a different version of raw_input(), 
> it's just a way of entering strings without having to type \\ when you 
> need \.)
> 
> -- 
> Bartc

Hey Bartc

I'm sorry about getting you confused, I did try that, but it didn't work, maybe 
it was me, but now I've tried it again it does work.

I've now managed to get the file to be created and write to the file so its all 
working fine.

The only question left is when I've conducted a search through all the drives 
for a browser .exe file, how do I take the search results and put them in to a 
text file, but I guess that's for another thread.

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


Untrusted code execution

2016-04-03 Thread Jon Ribbens
I'd just like to say up front that this is more of a thought experiment
than anything else, I don't have any plans to use this idea on any
genuinely untrusted code. Apart from anything else, there's the
denial-of-service issue.

That said, is there any way that the following Python 3.4 code could
result in a arbitrary code execution security hole?

tree = compile(untrusted_code, "

Re: Plot/Graph

2016-04-03 Thread Muhammad Ali
On Sunday, April 3, 2016 at 2:04:45 PM UTC-7, Michael Selik wrote:
> Indeed there is. Every example in the gallery shows the code to produce it.
> 
> http://matplotlib.org/gallery.html
> 
> On Sun, Apr 3, 2016, 8:05 PM Muhammad Ali 
> wrote:
> 
> >
> > Hi,
> >
> > Could anybody tell me that how can I plot graphs by matplotlib and get
> > expertise in a short time? I have to plot 2D plots just like origin
> > software.
> >
> > Secondly, how could we draw some horizontal reference line at zero when
> > the vertical scale is from -3 to 3?
> >
> > Looking for your posts, please.
> >
> > Thank you.
> >
> > p.s: Is there any short and to the point text book/manual/pdf to learn 2D
> > plotting with matplotlib?
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >

Thank you for your post.

 How do I convert/change/modify python script so that my data could be 
extracted according to python script and at the end it generates another single 
extracted data file instead of displaying/showing some graph? So that, I can 
manually plot the newly generated file (after data extraction) by some other 
software like origin.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread Erik

Loop.IO:

On 03/04/16 21:25, Loop.IO wrote:

On Sunday, April 3, 2016 at 9:15:22 PM UTC+1, Erik wrote:

On 03/04/16 20:54, Loop.IO wrote:

The original post said what did happen, the code runs and hangs on
the create file, and once i press Enter it then finishes and creates
the file, not sure how you missed that but thanks


Yes, I read your original post. That was days ago.

The comment I was replying to was you telling BartC that what he had
suggested "didn't work" (with no further information).

Please pay attention to the context of the email you are responding to.

E.


Erik

It was a syntax error. But sure, thanks.


So, you reply to my advisory on how to report your problem by saying 
that your original post said what did happen. Your original post said:


"the code runs and hangs on the create file, and once i press Enter it 
then finishes and creates the file"


But it turns out that "It was a syntax error".

If it was a syntax error, them how did the code run and "hang on the 
create file"?


Don't try to sweep my suggestion (that you should describe your symptoms 
properly) under the carpet. It's a very important lesson to learn for 
people trying to report bugs/issues.


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


Re: Plot/Graph

2016-04-03 Thread Oscar Benjamin
On 3 Apr 2016 22:21, "Muhammad Ali"  wrote:
>
>  How do I convert/change/modify python script so that my data could be
extracted according to python script and at the end it generates another
single extracted data file instead of displaying/showing some graph? So
that, I can manually plot the newly generated file (after data extraction)
by some other software like origin.

It depends what you're computing and what format origin expects the data to
be in. Presumably it can use CSV files so take a look at the CSV module
which can write these.

(You'll get better answers to a question like this if you show us some code
and ask a specific question about how to change it.)

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


Re: Failed to update the os.environ with subprocess.Popen.

2016-04-03 Thread Cameron Simpson

On 03Apr2016 11:24, Hongyi Zhao  wrote:

On Sun, 03 Apr 2016 18:20:31 +1000, Cameron Simpson wrote:


In particular, you want the subprocess' output. As written, your code
sets "output" to the Popen object. You actually want to set it to the
.stdout attribute of that object, which is the output from the
subcommand.


Based on your above hints, I try to use the following codes:

output = Popen("""
/bin/bash <
   os.environ.update(line.partition('=')[::2] for line in output.split
('\0'))
AttributeError: 'NoneType' object has no attribute 'split'


Please have a close read of the subprocess docs as Steven recommended.

You're calling:

 output.split('\0')

The message above indicates that "output" is None. This is probably because you 
have not asked to attach to the command's output in your Popen() call, and 
therefore stdout is not attached to a pipe, so it is None.


Also note that even when it is attached to a pipe, .stdout is a _file_. So you 
need to read from it to get a string to split.



While the following code will work smoothly:

output = Popen("""
/bin/bash <

This is because (a) you specified stdout=PIPE here, which you did not do 
earlier and (b) because .communicate reads the output for you and gives you a 
string.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread Loop.IO
On Sunday, April 3, 2016 at 10:27:16 PM UTC+1, Erik wrote:
> Loop.IO:
> 
> On 03/04/16 21:25, Loop.IO wrote:
> > On Sunday, April 3, 2016 at 9:15:22 PM UTC+1, Erik wrote:
> >> On 03/04/16 20:54, Loop.IO wrote:
> >>> The original post said what did happen, the code runs and hangs on
> >>> the create file, and once i press Enter it then finishes and creates
> >>> the file, not sure how you missed that but thanks
> >>
> >> Yes, I read your original post. That was days ago.
> >>
> >> The comment I was replying to was you telling BartC that what he had
> >> suggested "didn't work" (with no further information).
> >>
> >> Please pay attention to the context of the email you are responding to.
> >>
> >> E.
> >
> > Erik
> >
> > It was a syntax error. But sure, thanks.
> 
> So, you reply to my advisory on how to report your problem by saying 
> that your original post said what did happen. Your original post said:
> 
> "the code runs and hangs on the create file, and once i press Enter it 
> then finishes and creates the file"
> 
> But it turns out that "It was a syntax error".
> 
> If it was a syntax error, them how did the code run and "hang on the 
> create file"?
> 
> Don't try to sweep my suggestion (that you should describe your symptoms 
> properly) under the carpet. It's a very important lesson to learn for 
> people trying to report bugs/issues.
> 
> E.

I think you've misunderstood chap

My initial issue didn't have a syntax error, it just hung in the code until I 
pressed Enter/Return.

I then tried Bartc's solution when I changed my code, which I then replied "it 
doesn't work", which as you pointed out was unhelpful.

You now seem to be on some sort of rampage as I've already recognised that it 
was short, and said I got a syntax error upon attempting the new code that 
Bartc provided. I then said thanks to you for pointing it out, if you want to 
call that sweeping it under the carpet, then so be it, but the issue was 
resolved.

That's really the end of the matter, whether you're fishing for some sort of 
recognition or brownie points I don't know, but try relaxing and taking a step 
back; the issue is resolved, I'm moving on with the program, I appreciate the 
replies from everyone (including you) so chill.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread Erik

On 03/04/16 22:49, Loop.IO wrote:

You now seem to be on some sort of rampage


I offered you some valuable advice.

*plonk*

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


Re: Plot/Graph

2016-04-03 Thread Muhammad Ali
On Sunday, April 3, 2016 at 2:35:58 PM UTC-7, Oscar Benjamin wrote:
> On 3 Apr 2016 22:21, "Muhammad Ali"  wrote:
> >
> >  How do I convert/change/modify python script so that my data could be
> extracted according to python script and at the end it generates another
> single extracted data file instead of displaying/showing some graph? So
> that, I can manually plot the newly generated file (after data extraction)
> by some other software like origin.
> 
> It depends what you're computing and what format origin expects the data to
> be in. Presumably it can use CSV files so take a look at the CSV module
> which can write these.
> 
> (You'll get better answers to a question like this if you show us some code
> and ask a specific question about how to change it.)
> 
> --
> Oscar

How could the python script be modified to generate data file rather than 
display a plot by using matplotlib?


def make_plot(plot):
indent = plot.plot_options.indent
args = plot.plot_options.args
# Creating the plot
print ('Generating the plot...')
fig = plt.figure(figsize=(plot.fig_width_inches,plot.fig_height_inches))
ax = fig.add_subplot(111)
# Defining the color schemes.
print (indent + '>>> Using the "' + plot.cmap_name + '" colormap.')
if(plot.plot_options.using_default_cmap and not args.running_from_GUI):
print (2 * indent + 'Tip: You can try different colormaps by either:')
print (2 * indent + ' * Running the plot tool with the option 
-icmap n, ' \
   'with n in the range from 0 to', len(plot.plot_options.cmaps) - 
1)
print (2 * indent + ' * Running the plot tool with the option 
"-cmap cmap_name".')
print (2 * indent + '> Take a look at')
print (4 * indent + 
'')
print (2 * indent + '  for a list of colormaps, or run')
print (4 * indent + '"./plot_unfolded_EBS_BandUP.py --help".')

# Building the countour plot from the read data
# Defining the (ki,Ej) grid.
if(args.interpolation is not None):
ki = np.linspace(plot.kmin, plot.kmax, 2 * len(set(plot.KptsCoords)) + 
1, endpoint=True)
Ei = np.arange(plot.emin, plot.emax + plot.dE_for_hist2d, 
plot.dE_for_hist2d)
# Interpolating
grid_freq = griddata((plot.KptsCoords, plot.energies), plot.delta_Ns, 
(ki[None,:], Ei[:,None]), 
 method=args.interpolation, fill_value=0.0)
else:
ki = np.unique(np.clip(plot.KptsCoords, plot.kmin, plot.kmax))
Ei = np.unique(np.clip(plot.energies, plot.emin,  plot.emax))
grid_freq = griddata((plot.KptsCoords, plot.energies), plot.delta_Ns, 
(ki[None,:], Ei[:,None]), 
 method='nearest', fill_value=0.0)

if(not args.skip_grid_freq_clip):
grid_freq = grid_freq.clip(0.0) # Values smaller than zero are just 
noise.
# Normalizing and building the countour plot
manually_normalize_colorbar_min_and_maxval = False
if((args.maxval_for_colorbar is not None) or (args.minval_for_colorbar is 
not None)):
manually_normalize_colorbar_min_and_maxval = True
args.disable_auto_round_vmin_and_vmax = True
maxval_for_colorbar = args.maxval_for_colorbar
minval_for_colorbar = args.minval_for_colorbar
else:
if not args.disable_auto_round_vmin_and_vmax:
minval_for_colorbar = float(round(np.min(grid_freq)))
maxval_for_colorbar = float(round(np.max(grid_freq)))
args.round_cb = 0
if(manually_normalize_colorbar_min_and_maxval or not 
args.disable_auto_round_vmin_and_vmax):
modified_vmin_or_vmax = False
if not args.disable_auto_round_vmin_and_vmax and not 
args.running_from_GUI:
print (plot.indent + '* Automatically renormalizing color scale '\
   '(you can disable this with the option 
--disable_auto_round_vmin_and_vmax):')
if manually_normalize_colorbar_min_and_maxval:
print (plot.indent + '* Manually renormalizing color scale')
if(minval_for_colorbar is not None):
previous_vmin = np.min(grid_freq)
if(abs(previous_vmin - minval_for_colorbar) >= 0.1):
modified_vmin_or_vmax = True
print (2 * indent + 'Previous vmin = %.1f, new vmin = %.1f' % 
(previous_vmin, 
   
minval_for_colorbar))
else:
minval_for_colorbar = np.min(grid_freq)
if(maxval_for_colorbar is not None):
previous_vmax = np.max(grid_freq)
if(abs(previous_vmax - maxval_for_colorbar) >= 0.1):
modified_vmin_or_vmax = True
print (2 * indent + 'Previous vmax = %.1f, new vmax = %.1f' % 
(previous_vmax, 
   
maxval_for_colorbar))
else:
maxval_for_c

Re: Plot/Graph

2016-04-03 Thread MRAB

On 2016-04-04 01:04, Muhammad Ali wrote:

On Sunday, April 3, 2016 at 2:35:58 PM UTC-7, Oscar Benjamin wrote:

On 3 Apr 2016 22:21, "Muhammad Ali"  wrote:
>
>  How do I convert/change/modify python script so that my data could be
extracted according to python script and at the end it generates another
single extracted data file instead of displaying/showing some graph? So
that, I can manually plot the newly generated file (after data extraction)
by some other software like origin.

It depends what you're computing and what format origin expects the data to
be in. Presumably it can use CSV files so take a look at the CSV module
which can write these.

(You'll get better answers to a question like this if you show us some code
and ask a specific question about how to change it.)

--
Oscar


How could the python script be modified to generate data file rather than 
display a plot by using matplotlib?


def make_plot(plot):
 indent = plot.plot_options.indent
 args = plot.plot_options.args
 # Creating the plot
 print ('Generating the plot...')
 fig = plt.figure(figsize=(plot.fig_width_inches,plot.fig_height_inches))
 ax = fig.add_subplot(111)
 # Defining the color schemes.
 print (indent + '>>> Using the "' + plot.cmap_name + '" colormap.')
 if(plot.plot_options.using_default_cmap and not args.running_from_GUI):
 print (2 * indent + 'Tip: You can try different colormaps by either:')
 print (2 * indent + ' * Running the plot tool with the option 
-icmap n, ' \
'with n in the range from 0 to', len(plot.plot_options.cmaps) - 
1)
 print (2 * indent + ' * Running the plot tool with the option "-cmap 
cmap_name".')
 print (2 * indent + '> Take a look at')
 print (4 * indent + 
'')
 print (2 * indent + '  for a list of colormaps, or run')
 print (4 * indent + '"./plot_unfolded_EBS_BandUP.py --help".')

 # Building the countour plot from the read data
 # Defining the (ki,Ej) grid.
 if(args.interpolation is not None):
 ki = np.linspace(plot.kmin, plot.kmax, 2 * len(set(plot.KptsCoords)) + 
1, endpoint=True)
 Ei = np.arange(plot.emin, plot.emax + plot.dE_for_hist2d, 
plot.dE_for_hist2d)
 # Interpolating
 grid_freq = griddata((plot.KptsCoords, plot.energies), plot.delta_Ns, 
(ki[None,:], Ei[:,None]),
  method=args.interpolation, fill_value=0.0)
 else:
 ki = np.unique(np.clip(plot.KptsCoords, plot.kmin, plot.kmax))
 Ei = np.unique(np.clip(plot.energies, plot.emin,  plot.emax))
 grid_freq = griddata((plot.KptsCoords, plot.energies), plot.delta_Ns, 
(ki[None,:], Ei[:,None]),
  method='nearest', fill_value=0.0)

 if(not args.skip_grid_freq_clip):
 grid_freq = grid_freq.clip(0.0) # Values smaller than zero are just 
noise.
 # Normalizing and building the countour plot
 manually_normalize_colorbar_min_and_maxval = False
 if((args.maxval_for_colorbar is not None) or (args.minval_for_colorbar is 
not None)):
 manually_normalize_colorbar_min_and_maxval = True
 args.disable_auto_round_vmin_and_vmax = True
 maxval_for_colorbar = args.maxval_for_colorbar
 minval_for_colorbar = args.minval_for_colorbar
 else:
 if not args.disable_auto_round_vmin_and_vmax:
 minval_for_colorbar = float(round(np.min(grid_freq)))
 maxval_for_colorbar = float(round(np.max(grid_freq)))
 args.round_cb = 0
 if(manually_normalize_colorbar_min_and_maxval or not 
args.disable_auto_round_vmin_and_vmax):
 modified_vmin_or_vmax = False
 if not args.disable_auto_round_vmin_and_vmax and not 
args.running_from_GUI:
 print (plot.indent + '* Automatically renormalizing color scale '\
'(you can disable this with the option 
--disable_auto_round_vmin_and_vmax):')
 if manually_normalize_colorbar_min_and_maxval:
 print (plot.indent + '* Manually renormalizing color scale')
 if(minval_for_colorbar is not None):
 previous_vmin = np.min(grid_freq)
 if(abs(previous_vmin - minval_for_colorbar) >= 0.1):
 modified_vmin_or_vmax = True
 print (2 * indent + 'Previous vmin = %.1f, new vmin = %.1f' % 
(previous_vmin,

minval_for_colorbar))
 else:
 minval_for_colorbar = np.min(grid_freq)
 if(maxval_for_colorbar is not None):
 previous_vmax = np.max(grid_freq)
 if(abs(previous_vmax - maxval_for_colorbar) >= 0.1):
 modified_vmin_or_vmax = True
 print (2 * indent + 'Previous vmax = %.1f, new vmax = %.1f' % 
(previous_vmax,
 

How to make sphinx to recognize functools.partial?

2016-04-03 Thread George Trojan

Yet another sphinx question. I am a beginner here.

I can't make sphinx to recognize the following (abbreviated) code:

'''
module description

:func:`~pipe` and :func:`~spipe` read data passed by LDM's `pqact`.

'''

def _pipe(f, *args):
'''doc string'''
 pass

def _get_msg_spipe():
'''another doc'''
 pass

spipe = functools.partial(_pipe, _get_msg_spipe)
spipe._doc_ = '''
Loop over data feed on `stdin` from LDM via SPIPE.
'''

The word spipe is rendered correctly in html, but the link is not created.

I did put a print statement in sphinx/util/inspect.py, it appears that 
spipe definition is not recognized. I am running sphinx 1.3.5, according 
to CHANGELOG functools.partial support was added in 1.2.1.


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


Re: How to make sphinx to recognize functools.partial?

2016-04-03 Thread MRAB

On 2016-04-04 01:26, George Trojan wrote:

Yet another sphinx question. I am a beginner here.

I can't make sphinx to recognize the following (abbreviated) code:

'''
module description

:func:`~pipe` and :func:`~spipe` read data passed by LDM's `pqact`.

'''

def _pipe(f, *args):
  '''doc string'''
   pass

def _get_msg_spipe():
  '''another doc'''
   pass

spipe = functools.partial(_pipe, _get_msg_spipe)
spipe._doc_ = '''
  Loop over data feed on `stdin` from LDM via SPIPE.
'''

The word spipe is rendered correctly in html, but the link is not created.

I did put a print statement in sphinx/util/inspect.py, it appears that
spipe definition is not recognized. I am running sphinx 1.3.5, according
to CHANGELOG functools.partial support was added in 1.2.1.


Is it anything to do with "spipe._doc_"? Should that be "spipe.__doc__"?

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


ONE CLICK REST API

2016-04-03 Thread David Shi via Python-list
Eclipse has got one click app for creating REST services.
What is it equivalent in Python?
Regards.
David
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Threading is foobared?

2016-04-03 Thread Mark Sapiro
Mark Sapiro wrote:
> Random832 wrote:
> 
>> Any chance that it could fix reference headers to match?
>> 
>> Actually, merely prepending the original Message-ID itself to the
>> references header might be enough to change the reply's situation from
>> "nephew" ("reply to [missing] sibling") to "grandchild" ("reply to
>> [missing] reply"), which might be good enough to make threading work
>> right on most clients, and would be *easy* (whereas maintaining an
>> ongoing reversible mapping may not be).
>> 
>> And if it's not too much additional work, maybe throw in an
>> X-Mailman-Original-Message-ID (and -References if anything is done with
>> that) field, so that the original state can be recovered.
> 
> 
> I think these are good ideas. I'm going to try to do something along
> these lines.


This is now implemented on mail.python.org for [email protected]
and the others that gateway to Usenet.

I hope this will mitigate at least some of the threading issues.

As noted earlier in this thread, the original Message-ID: is appended,
not prepended to References:. More specifically, if there is a
References: header, the original Message-ID: is appended. If not, one is
created with the In-Reply-To: value if any and the original Message-ID:.

-- 
Mark Sapiro The highway is for gamblers,
San Francisco Bay Area, Californiabetter use your sense - B. Dylan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sorting a list

2016-04-03 Thread Peter Otten
DFS wrote:

> On 4/3/2016 3:31 PM, Peter Otten wrote:

> from operator import itemgetter as get
> print "\n".join("{1} {0}".format(*p) for p in sorted(
>> ... sorted(colCounts, key=get(1)), key=get(0), reverse=True))
> 
> Kind of clunky looking.  Is that why don't you recommend it?

That, and you produce two intermediate lists and an intermediate string. For 
larger input data this may produce significant overhead.

>> You could also cheat and use
>>
>> lambda v: (-v[0], v[1])
>>
>> and a single sorted().
> 
> That works well.  Why is it 'cheating'?

On second thought it isn't ;)

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