Re: "Python launcher" required to run *.py scripts on Windows?

2017-06-27 Thread Terry Reedy

On 6/27/2017 1:41 AM, Ben S. via Python-list wrote:

As I observed v3.6.1 installs (on Windows 7) in addition to the core python engine a 
second program "Python Launcher".

As far as I read this component seems to be not necessary since it only aims to 
facilitate the handling with *.py scripts on Windows.

When I always call Python script from CommandPrompt like

D:\tools\Python\python.exe mypythonscript.py

then this Launcher should not be necessary.

Am I right?


As long as you have only 1 version of python installed, then there is no 
ambiguity to 'python', and you do not really need it.  But it is nice to 
be able to type 'py' regardless of the current working directory.


If you have more than 1 python version installed, it is very handy.


Since I prefer to have as less prgrams installed as possible I consider to 
uninstall the Python Launcher.

Is this possible without causing trouble to Python executions?

Ben




--
Terry Jan Reedy

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


Re: Syntax error for simple script

2017-06-27 Thread Steve D'Aprano
On Tue, 27 Jun 2017 03:00 am, mm0fmf wrote:

> Sorry to victim blame but why can't people copy the error message into a
> search engine, such as Google, and see what the problem is themselves?

You're not victim blaming. There's no *victim* here, syntax errors are a part of
programming and one has to learn to deal with them. That's like a sketch artist
whose pencil lead snaps. It happens, and dealing with it is part of the job.

We're volunteers, not being paid for our time, and while we're happy to help
people with problems the implied social contract goes both ways: people should
make an honest effort to solve the problem themselves before asking us to solve
it for them.

So you're right to ask whether or not the OP tried googling for the error
message first. Nothing to apologise for.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: "Python launcher" required to run *.py scripts on Windows?

2017-06-27 Thread Ned Batchelder
On Tuesday, June 27, 2017 at 1:41:22 AM UTC-4, Ben S. wrote:
> As I observed v3.6.1 installs (on Windows 7) in addition to the core python 
> engine a second program "Python Launcher".
> 
> As far as I read this component seems to be not necessary since it only aims 
> to facilitate the handling with *.py scripts on Windows.
> 
> When I always call Python script from CommandPrompt like
> 
> D:\tools\Python\python.exe mypythonscript.py
> 
> then this Launcher should not be necessary.
> 
> Am I right?
> 
> Since I prefer to have as less prgrams installed as possible I consider to 
> uninstall the Python Launcher.
> 
> Is this possible without causing trouble to Python executions?

Micro-managing installations like this seems like a bad idea.  If Python
installed it, and you are not running out of disk space, then leave it
alone.

Perhaps Python will be fine if you remove the launcher, but it's
a bad habit to pursue: other software will be harder to untangle, and
when problems occur, others will be unable to help because you will now
have a completely unique and unsupported configuration.

Is there some problem you are trying to solve by removing the launcher?

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


Re: "Python launcher" required to run *.py scripts on Windows?

2017-06-27 Thread Andre Müller
Double Post:
https://python-forum.io/Thread-Python-launcher-required-to-run-py-scripts-on-Windows

Pleas don't do this. It's not a nice behavior.

Thanks.

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


Converting sentences to vector form

2017-06-27 Thread Bhaskar Dhariyal
Hi,

I am doing a project on data science. I need to convert sentences to vectorial 
form. I have already written code for cleansing data and already removed stop 
words and performed stemming. Please help in converting kickdesc and kickkey to 
vectorial form.

Link to code and dataset: 
https://drive.google.com/open?id=0B1D4AyluMGU0Uk5qYUk3dVAtd00

Apologoes for ugly code

Thanks 

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


Re: Converting sentences to vector form

2017-06-27 Thread Ben Bacarisse
Bhaskar Dhariyal  writes:

> I am doing a project on data science. I need to convert sentences to
> vectorial form.

That's not a term I am familiar with.  If it's standard, that's my
fault, but you can still help people like me by explaining what you
mean.  And if it is not a standard term then people will just be
guessing what "vectorial form" is.

If it's hard to define you can still help us by showing a few simple
examples.  Give some sentences, and then give the "vectorial form".


> Link to code and dataset:
> https://drive.google.com/open?id=0B1D4AyluMGU0Uk5qYUk3dVAtd00

Not everyone is going to follow a link to try to find out what you
need.  Put as much as you can in the actual posting.

> Apologoes for ugly code

I didn't find anything there that helped me understand the problem but
that may be because I don't have IPython.  Maybe loading the ipynb file
would show me some code, but it would, again, be better to post the code
you are having trouble with here.

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


Re: Converting sentences to vector form

2017-06-27 Thread Bhaskar Dhariyal
You can't train a model on words. You need to convert it into numerical 
form(vector form). For this there are some packages like word2vec and doc2vec. 

Thanks for replying 


On Tuesday, 27 June 2017 16:37:56 UTC+5:30, Ben Bacarisse  wrote:
> Bhaskar Dhariyal  writes:
> 
> > I am doing a project on data science. I need to convert sentences to
> > vectorial form.
> 
> That's not a term I am familiar with.  If it's standard, that's my
> fault, but you can still help people like me by explaining what you
> mean.  And if it is not a standard term then people will just be
> guessing what "vectorial form" is.
> 
> If it's hard to define you can still help us by showing a few simple
> examples.  Give some sentences, and then give the "vectorial form".
> 
> 
> > Link to code and dataset:
> > https://drive.google.com/open?id=0B1D4AyluMGU0Uk5qYUk3dVAtd00
> 
> Not everyone is going to follow a link to try to find out what you
> need.  Put as much as you can in the actual posting.
> 
> > Apologoes for ugly code
> 
> I didn't find anything there that helped me understand the problem but
> that may be because I don't have IPython.  Maybe loading the ipynb file
> would show me some code, but it would, again, be better to post the code
> you are having trouble with here.
> 
> -- 
> Ben.

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


argparse epilog call function?

2017-06-27 Thread Didymus
Greetings,

I might be barking up the wrong tree, but was wondering if there's a way to 
have the argpasre epilog call a function. for example:

epilog=Examples()

Where Examples is:

def Examples():
text = """Lots of examples"""
print(text.format())

I've place this in and found that it prints out no matter if I use the -h or
not and also it prints first If I do:

epilog='Single Example'

it works as intended, unfortunately, I need to show several examples. Just 
wondering if someone has found a why to do this (without making a custom help).

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


Re: Syntax error for simple script

2017-06-27 Thread Steve D'Aprano
On Tue, 27 Jun 2017 08:34 am, Erik wrote about the print function error message:

py> print x
  File "", line 1
print x
  ^
SyntaxError: Missing parentheses in call to 'print'


> To be fair, this already seems to be a special case:
[...]
>  >>> len "bar"
>File "", line 1
>  len "bar"
>  ^
> SyntaxError: invalid syntax

Correct, the print function is singled out as a special case, because people are
unlikely to come across tutorials telling them to write

   len "bar"


> If that's the case, then why make it so terse? It's presumably there as
> a special case specifically to tell/remind people that print became a
> function in Py3.

Indeed. But it is hardly terse: it's a full sentence:

Missing parentheses in call to 'print'

(although missing the full stop at the end, if anyone cares enough to raise a
bug report for that).


> I think the suggestion above is a bit wordy, but even if it was
> something like "Missing parentheses in call to the 'print' function"

I think this is a good example of "the curse of knowledge". Its hard for experts
to think like a non-expert.

It seems obvious to us that adding the word "function" will make it clear to the
user what's going on. We understand that print is now a function, and function
calls always need parentheses, but that print used to be a statement like
while, for, if, etc. that doesn't need parentheses.

To a moderately experienced programmer, the word "function" doesn't actually add
anything, but it isn't harmful: the error is just a reminder of what they
probably already know.

But to the beginner, adding "function" at the error might as well be 

Missing parentheses in call to the 'print' wharrgarbl.


It's just jargon. They can either diagnose the problem from the first part of
the sentence telling them that there are missing parentheses, or they can't. If
they can't, I doubt that adding the word "function" (or any other jargon term
like subroutine, procedure or callable) will help.

Anyway, that's my opinion. If any newbies, like the OP, would like to venture an
opinion, that would be good. That's why I asked Ben if there was something we
could do to make the sentence clearer.



> or 
> even "Missing parentheses in call to 'print'. Using 'print' as a
> statement is obsolete syntax in Python 3." ... or whatever is considered
> more descriptive.

When it comes to error messages, more is not always better. There is a balance
needed between too terse and too verbose and wordy.

Users don't read error messages, even when they are well-written:

https://ux.stackexchange.com/questions/393/how-do-i-get-users-to-read-error-messages

https://stackoverflow.com/questions/2356698/how-to-get-users-to-read-error-messages

so adding more words is not necessarily going to help beginners. In fact it
might even make it *less* likely that they read the error. Reading error
messages is a skill that needs to be learned, or taught.


> Either that or just make it "SyntaxError: invalid syntax" like all the
> others.

We've been there: adding the specific print message is new to Python 3.5 (or
maybe 3.4, I forget which). Python 3.3 gives just "SyntaxError: invalid
syntax".



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: argparse epilog call function?

2017-06-27 Thread Chris Angelico
On Tue, Jun 27, 2017 at 11:55 PM, Didymus  wrote:
> Greetings,
>
> I might be barking up the wrong tree, but was wondering if there's a way to 
> have the argpasre epilog call a function. for example:
>
> epilog=Examples()
>
> Where Examples is:
>
> def Examples():
> text = """Lots of examples"""
> print(text.format())
>
> I've place this in and found that it prints out no matter if I use the -h or
> not and also it prints first If I do:
>
> epilog='Single Example'
>
> it works as intended, unfortunately, I need to show several examples. Just 
> wondering if someone has found a why to do this (without making a custom 
> help).

The way you've written it, Examples() will be called before argparse
does its work, and whatever it returns becomes the epilog. Can you
work your function such that it returns a string, instead of printing
something? Or is it a very expensive function?

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


Re: argparse epilog call function?

2017-06-27 Thread Fox


what  " -h " are you even talkin bout ?




def Examples():
text = """Lots of examples"""
print(text.format())



epilog='where the heck to put a -h ?? '

epilog=Examples()


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


Re: argparse epilog call function?

2017-06-27 Thread Chris Angelico
On Wed, Jun 28, 2017 at 12:09 AM, Fox  wrote:
> what  " -h " are you even talkin bout ?
>
>
>
>
> def Examples():
> text = """Lots of examples"""
> print(text.format())
>
>
>
> epilog='where the heck to put a -h ?? '
>
> epilog=Examples()

List admins, this person has been abusing the pydotorg-www list for
several days. Can he please be banned?

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


Re: "Python launcher" required to run *.py scripts on Windows?

2017-06-27 Thread eryk sun
On Tue, Jun 27, 2017 at 5:41 AM, Ben S. via Python-list
 wrote:
>
> When I always call Python script from CommandPrompt like
>
> D:\tools\Python\python.exe mypythonscript.py
>
> then this Launcher should not be necessary.

The launcher implements shebang support for directly running Python
scripts in multiple versions and virtual environments, including
virtual commands (defined in py.ini) to support other implementations
such as PyPy. It can also be used to administer multiple CPython
installations from the command line.

If you don't need it, don't install it. You can install it later if
you change your mind.
-- 
https://mail.python.org/mailman/listinfo/python-list


A Good Tutorial on Python Decorators

2017-06-27 Thread Saurabh Chaturvedi
https://opensource.google.com/projects/py-decorators-tutorial

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


A million requests per second with Python

2017-06-27 Thread Sam Chats
https://medium.freecodecamp.com/million-requests-per-second-with-python-95c137af319
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: argparse epilog call function?

2017-06-27 Thread Peter Otten
Didymus wrote:

> Greetings,
> 
> I might be barking up the wrong tree, but was wondering if there's a way
> to have the argpasre epilog call a function. for example:
> 
> epilog=Examples()
> 
> Where Examples is:
> 
> def Examples():
> text = """Lots of examples"""
> print(text.format())
> 
> I've place this in and found that it prints out no matter if I use the -h
> or not and also it prints first If I do:
> 
> epilog='Single Example'
> 
> it works as intended, unfortunately, I need to show several examples. Just
> wondering if someone has found a why to do this (without making a custom
> help).

Here's a way using a custom *formatter*:

$ cat epilog.py
import argparse

class MyHelpFormatter(argparse.HelpFormatter):
def add_text(self, text):
if callable(text):
text = text()
return super().add_text(text)

def examples():
return "yadda yadda"

parser = argparse.ArgumentParser(
epilog=examples,
formatter_class=MyHelpFormatter
)
parser.add_argument("--foo")

parser.parse_args()
$ python3 epilog.py -h
usage: epilog.py [-h] [--foo FOO]

optional arguments:
  -h, --help  show this help message and exit
  --foo FOO

yadda yadda
$ 


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


Re: argparse epilog call function?

2017-06-27 Thread Didymus
On Tuesday, June 27, 2017 at 9:56:13 AM UTC-4, Didymus wrote:
> Greetings,
> 
> I might be barking up the wrong tree, but was wondering if there's a way to 
> have the argpasre epilog call a function. for example:
> 
> epilog=Examples()
> 
> Where Examples is:
> 
> def Examples():
> text = """Lots of examples"""
> print(text.format())
> 
> I've place this in and found that it prints out no matter if I use the -h or
> not and also it prints first If I do:
> 
> epilog='Single Example'
> 
> it works as intended, unfortunately, I need to show several examples. Just 
> wondering if someone has found a why to do this (without making a custom 
> help).
> 
> thanks
>   Tom
Well, I thought I had a good idea to work around this by setting a string to 
the formatted text and then use that string in the epilog:

text = Example()
#
parser = argparse.ArgumentParser(prog=sys.argv[0],
description="Example Arg Parse",
epilog=text)

I had to change the Example function to return the string and in a print it 
works fine, however when used in the argsparse, the formatting is lost...

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


Re: argparse epilog call function?

2017-06-27 Thread Didymus
On Tuesday, June 27, 2017 at 11:47:42 AM UTC-4, Didymus wrote:
> On Tuesday, June 27, 2017 at 9:56:13 AM UTC-4, Didymus wrote:
> > Greetings,
> > 
> > I might be barking up the wrong tree, but was wondering if there's a way to 
> > have the argpasre epilog call a function. for example:
> > 
> > epilog=Examples()
> > 
> > Where Examples is:
> > 
> > def Examples():
> > text = """Lots of examples"""
> > print(text.format())
> > 
> > I've place this in and found that it prints out no matter if I use the -h or
> > not and also it prints first If I do:
> > 
> > epilog='Single Example'
> > 
> > it works as intended, unfortunately, I need to show several examples. Just 
> > wondering if someone has found a why to do this (without making a custom 
> > help).
> > 
> > thanks
> >   Tom
> Well, I thought I had a good idea to work around this by setting a string to 
> the formatted text and then use that string in the epilog:
> 
> text = Example()
> #
> parser = argparse.ArgumentParser(prog=sys.argv[0],
> description="Example Arg Parse",
> epilog=text)
> 
> I had to change the Example function to return the string and in a print it 
> works fine, however when used in the argsparse, the formatting is lost...
> 
> -T

Greetings,

I got what I was looking for:

def Examples():
text = """Lots of examples"""
return text.format()

parser = argparse.ArgumentParser(prog=sys.argv[0],
formatter_class=argparse.RawTextHelpFormatter,
description="Argparse Example",
epilog=text)

The key here is the "formatter_class=argparse.RawTestHelpFormatter". Once I set 
that the epilog prints out nicely formatted:

% ./test.py -h   
usage: ./test.py [-h] [-n NAME] [-f | -m | -r | -v] 

Argparse Example.

optional arguments:
  -h, --helpshow this help message and exit
  -n NAME, --name NAME  Name to be created.

Examples:
Ex 1:
./test.py -n juser

Ex 2:
./test.py -n juser -r

...

Thanks for all the help.
 -Tom
-- 
https://mail.python.org/mailman/listinfo/python-list


How to build a simple neural network in 9 lines of Python code

2017-06-27 Thread Sam Chats
https://medium.com/technology-invention-and-more/how-to-build-a-simple-neural-network-in-9-lines-of-python-code-cc8f23647ca1
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A Good Tutorial on Python Decorators

2017-06-27 Thread Peter Pearson
On Tue, 27 Jun 2017 15:10:53 + (UTC), Saurabh Chaturvedi wrote:
> https://opensource.google.com/projects/py-decorators-tutorial

"No Results found."

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


Re: A Good Tutorial on Python Decorators

2017-06-27 Thread Andre Müller
Activate JavaScript, then you can see the content.
I had the same problem.

Peter Pearson  schrieb am Di., 27. Juni 2017 um
18:35 Uhr:

> On Tue, 27 Jun 2017 15:10:53 + (UTC), Saurabh Chaturvedi wrote:
> > https://opensource.google.com/projects/py-decorators-tutorial
>
> "No Results found."
>
> --
> To email me, substitute nowhere->runbox, invalid->com.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Syntax error for simple script

2017-06-27 Thread boB Stepp
On Tue, Jun 27, 2017 at 9:05 AM, Steve D'Aprano
 wrote:
> On Tue, 27 Jun 2017 08:34 am, Erik wrote about the print function error 
> message:
>
> py> print x
>   File "", line 1
> print x
>   ^
> SyntaxError: Missing parentheses in call to 'print'

[snip]

>> I think the suggestion above is a bit wordy, but even if it was
>> something like "Missing parentheses in call to the 'print' function"
>
> I think this is a good example of "the curse of knowledge". Its hard for 
> experts
> to think like a non-expert.
>
> It seems obvious to us that adding the word "function" will make it clear to 
> the
> user what's going on. We understand that print is now a function, and function
> calls always need parentheses, but that print used to be a statement like
> while, for, if, etc. that doesn't need parentheses.
>
> To a moderately experienced programmer, the word "function" doesn't actually 
> add
> anything, but it isn't harmful: the error is just a reminder of what they
> probably already know.
>
> But to the beginner, adding "function" at the error might as well be
>
> Missing parentheses in call to the 'print' wharrgarbl.
>
>
> It's just jargon. They can either diagnose the problem from the first part of
> the sentence telling them that there are missing parentheses, or they can't. 
> If
> they can't, I doubt that adding the word "function" (or any other jargon term
> like subroutine, procedure or callable) will help.
>
> Anyway, that's my opinion. If any newbies, like the OP, would like to venture 
> an
> opinion, that would be good. That's why I asked Ben if there was something we
> could do to make the sentence clearer.

Perhaps add a simple usage example?

SyntaxError:  Missing parentheses in call to 'print'.  Correct example:
print('Prints this string')

Surely a little more verbiage won't be too harmful?

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


Re: How to build a simple neural network in 9 lines of Python code

2017-06-27 Thread Marko Rauhamaa
Sam Chats :

> https://medium.com/technology-invention-and-more/how-to-build-a-simpl
> e-neural-network-in-9-lines-of-python-code-cc8f23647ca1

Impressive, but APL's got Python beat. This one-liner implements the
Game of Life:

   life←{↑1 ⍵∨.∧3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵}

   https://en.wikipedia.org/wiki/APL_(programming_language)#Gam
   e_of_Life>

"Donc Dieu existe, répondez !"


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


Re: A Good Tutorial on Python Decorators

2017-06-27 Thread Paul Barry
Me doing the decorator thing (from a web dev point-of-view) at PyCon
Ireland 2015:

https://www.youtube.com/watch?v=My2UpCaN7rE

and here's a link to the PDF of my talk's material:
http://paulbarry.itcarlow.ie/pyconie2015/decorators.pdf

Paul.

On 27 June 2017 at 17:43, Andre Müller  wrote:

> Activate JavaScript, then you can see the content.
> I had the same problem.
>
> Peter Pearson  schrieb am Di., 27. Juni 2017 um
> 18:35 Uhr:
>
> > On Tue, 27 Jun 2017 15:10:53 + (UTC), Saurabh Chaturvedi wrote:
> > > https://opensource.google.com/projects/py-decorators-tutorial
> >
> > "No Results found."
> >
> > --
> > To email me, substitute nowhere->runbox, invalid->com.
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Paul Barry, t: @barrypj  - w:
http://paulbarry.itcarlow.ie - e: paul.ba...@itcarlow.ie
Lecturer, Computer Networking: Institute of Technology, Carlow, Ireland.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: argparse epilog call function?

2017-06-27 Thread breamoreboy
On Tuesday, June 27, 2017 at 3:25:10 PM UTC+1, Chris Angelico wrote:
> On Wed, Jun 28, 2017 at 12:09 AM, Fox  wrote:
> > what  " -h " are you even talkin bout ?
> >
> >
> >
> >
> > def Examples():
> > text = """Lots of examples"""
> > print(text.format())
> >
> >
> >
> > epilog='where the heck to put a -h ?? '
> >
> > epilog=Examples()
> 
> List admins, this person has been abusing the pydotorg-www list for
> several days. Can he please be banned?
> 
> ChrisA

I'll second that, the wxpython lists have been suffering similar abuse for 
several days.

Kindest regards.

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


Re: How to build a simple neural network in 9 lines of Python code

2017-06-27 Thread John Ladasky
On Tuesday, June 27, 2017 at 9:24:07 AM UTC-7, Sam Chats wrote:
> https://medium.com/technology-invention-and-more/how-to-build-a-simple-neural-network-in-9-lines-of-python-code-cc8f23647ca1

OK, that's cheating a bit, using Numpy.  It's a nice little program, but it 
leverages a huge, powerful library.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to build a simple neural network in 9 lines of Python code

2017-06-27 Thread Marko Rauhamaa
John Ladasky :
> OK, that's cheating a bit, using Numpy. It's a nice little program,
> but it leverages a huge, powerful library.

What would *not* be cheating? A language without a library would be
dead.


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



Re: Syntax error for simple script

2017-06-27 Thread Erik

On 27/06/17 15:05, Steve D'Aprano wrote:

On Tue, 27 Jun 2017 08:34 am, Erik wrote about the print function error message:

To be fair, this already seems to be a special case:

[...]

  >>> len "bar"
File "", line 1
  len "bar"
  ^
SyntaxError: invalid syntax


Correct, the print function is singled out as a special case, because people are
unlikely to come across tutorials telling them to write

len "bar"


Sure. My point was that it's obviously a special case and not a generic 
error message that would occur in the same situation with any other 
callables. Hence there is obviously a single, specific place in the 
parser code that could just be changed slightly if it would help. I 
haven't looked at the source code for this.



Indeed. But it is hardly terse: it's a full sentence:

Missing parentheses in call to 'print'


Right, but as in this case, it's likely to trip up a beginner who 
happens to be following a Py2 tutorial or copying Py2 examples from SO 
or somewhere. In fact, apart from those of us who switch between 
versions for different projects and just forget (old habits die hard), a 
beginner typing in a Py2 example is probably the only case where this 
error is seen.


So I don't understand the resistance to making the error be a bit more 
explicit about why it is being generated to help those users - it 
doesn't explain (the obvious reason) _why_ their tutorial/example gives 
them an error when it doesn't to the person who wrote the tutorial.



Note that I am *explicitly* making Py3 the "good guy" and Py2 the "bad 
guy" in all the wordings that I have given that mention a version number 
- it could even be something like "Missing parentheses in call to 
'print'. This is obsolete Python 2 syntax. Please use modern Python 3 
syntax.". This addresses ChrisA's issue with the proposed wordy error 
that he thought Py3 was playing second fiddle in that version.





One other possibility is that a beginner fires up Py3 and gets that 
"weird" (to them) error when they tried their tutorial or SO code and 
then finds out that if they fire up Py2 instead it just works. Now they 
might continue to use Py2 because it's "the one that works" for them.


I would suggest that making the error dissuade them from doing that (for 
the cost of a few tens of bytes) is a good thing.



I think the suggestion above is a bit wordy, but even if it was
something like "Missing parentheses in call to the 'print' function"


I think this is a good example of "the curse of knowledge". Its hard for expert 
> to think like a non-expert.


[snip]


But to the beginner, adding "function" at the error might as well be

Missing parentheses in call to the 'print' wharrgarbl.


You are concentrating on the detail of what I wrote. I don't care what 
the eventual wording is (and for sure, someone else is far more 
qualified than me to suggest wording that is better for a beginner). My 
point is simply that the error _could_ contain _some_ more information 
that addresses this issue for a beginner who may be typing in Py2 
examples that encourages them to seek out Py3 tutorials instead.



That's why I asked Ben if there was something we
could do to make the sentence clearer.


Exactly. Ben is an example of someone more qualified than me to suggest 
the correct words.



Either that or just make it "SyntaxError: invalid syntax" like all the
others.


We've been there: adding the specific print message is new to Python 3.5 (or
maybe 3.4, I forget which). Python 3.3 gives just "SyntaxError: invalid
syntax".


That surprises me, to be honest. I had presumed that the parser had just 
had the machinery for that message placed where the 'print' keyword used 
to be handled rather than ripping the whole thing out when it became a 
function. Interesting that it's a retrospective special case.


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


Re: How to build a simple neural network in 9 lines of Python code

2017-06-27 Thread alister
On Tue, 27 Jun 2017 22:34:18 +0300, Marko Rauhamaa wrote:

> John Ladasky :
>> OK, that's cheating a bit, using Numpy. It's a nice little program,
>> but it leverages a huge, powerful library.
> 
> What would *not* be cheating? A language without a library would be
> dead.
> 
> 
> Marko

true but for a realistic comparison you should probably count all the 
lines of code in the libruary



-- 
I cannot believe that God plays dice with the cosmos.
-- Albert Einstein, on the randomness of quantum mechanics
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to write add frequency in particular file by reading a csv file and then making a new file of multiple csv file by adding frequency

2017-06-27 Thread SANS SANTOSH
On Sat 24. Jun 2017 at 13:27, Mark Byrne  wrote:

> A problem (possibly the problem) is the lines which use the get function:
> count = frequency.get(word,0)
>
> Since the dictionary is empty at the start of the loop, the get function is
> passing a value of 0 to count and count1.
> The subsequent updates to the dictionary are applying a value of zero
>
> As a result, the file being written to contains count values of 0 for each
> word.
>
> Possible fix is to replace this:
>
> count = frequency.get(word,0)
> count1 = frequency.get(word1,0)
> if word1 == word:
> frequency[word] = count + count1
> else:
> frequency[word] = count
>
> with this:
>
> if word1 == word:
> if word in frequency:
> frequency[word] += 1
> else:
> frequency[word] = 1
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to build a simple neural network in 9 lines of Python code

2017-06-27 Thread Chris Angelico
On Wed, Jun 28, 2017 at 5:34 AM, Marko Rauhamaa  wrote:
> John Ladasky :
>> OK, that's cheating a bit, using Numpy. It's a nice little program,
>> but it leverages a huge, powerful library.
>
> What would *not* be cheating? A language without a library would be
> dead.

Sure, but there are different levels of cheating. Using a
general-purpose programming language and its standard library isn't
usually considered cheating, but using a language or library that's
specifically designed for this purpose is less about "hey look how
simple this is" and more about "hey look how awesome this lang/lib
is". Which is a perfectly reasonable thing to brag; Python is
beautifully expressive in the general case, but there are some amazing
tools for special purposes.

So I wouldn't call it cheating; it's a demonstration of the
expressiveness of numpy.

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


Re: how to write add frequency in particular file by reading a csv file and then making a new file of multiple csv file by adding frequency

2017-06-27 Thread Jerry Hill
On Fri, Jun 23, 2017 at 4:07 PM, Mark Byrne  wrote:

> Possible fix is to replace this:
>
> count = frequency.get(word,0)
> count1 = frequency.get(word1,0)
> if word1 == word:
> frequency[word] = count + count1
> else:
> frequency[word] = count
>
> with this:
>
> if word1 == word:
> if word in frequency:
> frequency[word] += 1
> else:
> frequency[word] = 1
>

Have you considered replacing your frequency dict with a
defaultdict(int)​?  That way you could boil the whole thing down to:

from collections import defaultdict
frequency = defaultdict(int)
...

...
if word1 == word:
frequency[word] += 1

The defaultdict takes care of the special case for you.  If the value is
missing, it's defaulted to 0.

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


Re: How to build a simple neural network in 9 lines of Python code

2017-06-27 Thread Marko Rauhamaa
alister :

> On Tue, 27 Jun 2017 22:34:18 +0300, Marko Rauhamaa wrote:
>
>> John Ladasky :
>>> OK, that's cheating a bit, using Numpy. It's a nice little program,
>>> but it leverages a huge, powerful library.
>> 
>> What would *not* be cheating? A language without a library would be
>> dead.
>
> true but for a realistic comparison you should probably count all the 
> lines of code in the libruary

How's that defined? Lines of Python? Lines of C? Lines of assembly?
Lines of microcode?

What is a line?


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


Re: How to build a simple neural network in 9 lines of Python code

2017-06-27 Thread Marko Rauhamaa
Chris Angelico :

> On Wed, Jun 28, 2017 at 5:34 AM, Marko Rauhamaa  wrote:
>> What would *not* be cheating? A language without a library would be
>> dead.
>
> Sure, but there are different levels of cheating. Using a
> general-purpose programming language and its standard library isn't
> usually considered cheating, but using a language or library that's
> specifically designed for this purpose is less about "hey look how
> simple this is" and more about "hey look how awesome this lang/lib
> is". Which is a perfectly reasonable thing to brag; Python is
> beautifully expressive in the general case, but there are some amazing
> tools for special purposes.
>
> So I wouldn't call it cheating; it's a demonstration of the
> expressiveness of numpy.

You saw the APL example, right? APL's standard runtime/library contains
most of Numpy functionality because that's what APL has been designed
for.

Is that cheating?


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


Re: How to build a simple neural network in 9 lines of Python code

2017-06-27 Thread Chris Angelico
On Wed, Jun 28, 2017 at 6:22 AM, Marko Rauhamaa  wrote:
> Chris Angelico :
>
>> On Wed, Jun 28, 2017 at 5:34 AM, Marko Rauhamaa  wrote:
>>> What would *not* be cheating? A language without a library would be
>>> dead.
>>
>> Sure, but there are different levels of cheating. Using a
>> general-purpose programming language and its standard library isn't
>> usually considered cheating, but using a language or library that's
>> specifically designed for this purpose is less about "hey look how
>> simple this is" and more about "hey look how awesome this lang/lib
>> is". Which is a perfectly reasonable thing to brag; Python is
>> beautifully expressive in the general case, but there are some amazing
>> tools for special purposes.
>>
>> So I wouldn't call it cheating; it's a demonstration of the
>> expressiveness of numpy.
>
> You saw the APL example, right? APL's standard runtime/library contains
> most of Numpy functionality because that's what APL has been designed
> for.
>
> Is that cheating?

No, for the same reason. What it demonstrates is the terseness of APL
when used for its exact use case.

Ultimately, everything is implemented using lower level code. Isn't it
impressive how easily a computer can add two integers? Trying to do
the same thing in dominoes takes a lot of code:

http://www.numberphile.com/videos/domino_circuit.html

Should we count program code in domino equivalence?

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


Check A million requests per second with Python

2017-06-27 Thread YOUR_NAME_HERE
Awesome! Python's becoming more of an all rounder!

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


Re: A million requests per second with Python

2017-06-27 Thread YOUR_NAME_HERE
Awesome! I love Python!

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


Re: How to build a simple neural network in 9 lines of Python code

2017-06-27 Thread Steve D'Aprano
On Wed, 28 Jun 2017 02:23 am, Sam Chats wrote:

>
https://medium.com/technology-invention-and-more/how-to-build-a-simple-neural-network-in-9-lines-of-python-code-cc8f23647ca1


The derivative of the sigmoid curve given is completely wrong.

def __sigmoid(self, x):
return 1 / (1 + exp(-x))

def __sigmoid_derivative(self, x):
return x * (1 - x)


Should be:

def __sigmoid_derivative(self, x):
return exp(x) / (1 + exp(x))**2



http://mathworld.wolfram.com/SigmoidFunction.html


I wish these neural networks would give a tutorial on how to do something
non-trivial where:

- your training data is not just a couple of bits;

- the function you want the neural network to perform is non-trivial.


E.g. I have a bunch of data:

['cheese', 'pirate', 'aardvark', 'vitamin', 'egg', 'moon']

and a set of flags:

[True, False, True, True, False, True]


and I want the network to predict that:

'calcium' -> False
'aluminium' -> True
'wood' -> True
'plastic' -> False


(The function is, "is there a duplicated vowel?")


-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: How to build a simple neural network in 9 lines of Python code

2017-06-27 Thread Steve D'Aprano
On Wed, 28 Jun 2017 06:19 am, Marko Rauhamaa wrote:

> alister :
> 
>> On Tue, 27 Jun 2017 22:34:18 +0300, Marko Rauhamaa wrote:
>>
>>> John Ladasky :
 OK, that's cheating a bit, using Numpy. It's a nice little program,
 but it leverages a huge, powerful library.
>>> 
>>> What would *not* be cheating? A language without a library would be
>>> dead.
>>
>> true but for a realistic comparison you should probably count all the
>> lines of code in the libruary
> 
> How's that defined? Lines of Python? Lines of C? Lines of assembly?
> Lines of microcode?
> 
> What is a line?

Microcode isn't text so it doesn't come in lines.

Obviously we're talking about source code, not object code, byte code or machine
code, since source code is the only one that is measured in lines rather than
bytes.


-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: How to build a simple neural network in 9 lines of Python code

2017-06-27 Thread Steve D'Aprano
On Wed, 28 Jun 2017 05:34 am, Marko Rauhamaa wrote:

> John Ladasky :
>> OK, that's cheating a bit, using Numpy. It's a nice little program,
>> but it leverages a huge, powerful library.
> 
> What would *not* be cheating? A language without a library would be
> dead.

Its not really nine lines of Python. It's nine lines of Python, to call a
library of many thousands of lines of C, Fortran and Python.

And its not really a neural *network* as such, more like just a single neuron.

Starting from scratch with just the Python language and standard library, no
external third party code, how quickly can you write a neural network? I think
the answer is probably a wee bit more than "nine lines".



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: How to build a simple neural network in 9 lines of Python code

2017-06-27 Thread Steve D'Aprano
On Wed, 28 Jun 2017 06:22 am, Marko Rauhamaa wrote:

> You saw the APL example, right? APL's standard runtime/library contains
> most of Numpy functionality because that's what APL has been designed
> for.
> 
> Is that cheating?


Of course not. That demonstrates beautifully (or perhaps "unreadably tersely")
that the APL language primitives are extremely powerful (too powerful?).

Apart from just your usual contrariness *wink* I don't know why you are
objecting to this. It should be obvious that if you allow the use of external
libraries that can contain arbitrary amounts of code, *without* counting that
external code towards your measure of code complexity, you get a bogus
measurement of code complexity.

(That's like manufacturers who can make things artificially cheaply because they
don't have to pay the full costs of their input and processes: they get their
raw materials subsidised, putting part of the cost on tax payers, and don't
have to pay for their pollution, making others pay the cost.)

Suppose I said that I can write a full featured, advanced GUI web browser,
complete with Javascript and a plug-in system, in just *two* lines of Python
code:

import webbrowser
webbrowser.open('http://www.example.com')


What an astonishingly powerful language Python must be! Other languages require
dozens of lines of code just to parse Javascript, let alone run it.

Except... I'm not really measuring the capability of *Python*, as such. Not if I
word it as I have. I haven't really implemented a web browser, I'm just using
an external web browser. If I wanted to change the parameters, lets say by
changing the Javascript keyword "true" to "truish", then my code would expand
from two lines to millions of lines.

My demo of launching an external process to do all the work is of no help at all
to assist a developer in estimating the expressiveness and power of the
language.

If I were more honest, I would say:

"Here is how I can launch a web browser using the Python standard library in
just two lines of code."

which is an honest description of what I did, and can allow people to make fair
comparisons. E.g. comparing Python to AcmeScript, where you write:


program myprogram
begin program
load library webbrowser
new string url copied from 'http://www.example.com'
with webbrowser
  begin
method = open
method.call url
  end
end program

(I made that language up, for the record, don't bother googling for it.)

That gives you a fair comparison of the language expressiveness and power.

Chris is right: saying that we can create a simple neural network in 9 lines of
Python plus numpy allows fair comparison to other combinations of language and
library. Implying that it's just Python alone does not.




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Syntax error for simple script

2017-06-27 Thread Steve D'Aprano
On Wed, 28 Jun 2017 05:38 am, Erik wrote:


[...]
> So I don't understand the resistance to making the error be a bit more
> explicit about why it is being generated to help those users - it
> doesn't explain (the obvious reason) _why_ their tutorial/example gives
> them an error when it doesn't to the person who wrote the tutorial.

All of this is irrelevant if beginners don't read the error message. End-users
don't read error messages, no matter how well written they are, and every word
you add probably cuts the number of people reading it by half.

Newbie programmers are more like end-users than seasoned programmers. Learning
to read the error message is a skill that must be taught and learned. Part of
the learning process is to explain the why, the when, the how, and perhaps even
the history of the error. That's not something needed in the error message
itself (imagine how annoying it would be if ZeroDivisionError tried to explain
the basis of arithmetic and why you can't divide by zero), and rather than
helping the newbie, it will probably intimidate them and make it even less
likely to read and understand the error.

When designing an error message, imagine that you are going to read it a dozen
times a day, every day, for the rest of your career.


> One other possibility is that a beginner fires up Py3 and gets that
> "weird" (to them) error when they tried their tutorial or SO code and
> then finds out that if they fire up Py2 instead it just works. Now they
> might continue to use Py2 because it's "the one that works" for them.
> 
> I would suggest that making the error dissuade them from doing that (for
> the cost of a few tens of bytes) is a good thing.

The cost isn't ten bytes. The cost is human attention span.

Don't think of the newbie reading the error for the first time, because that
only happens *once*. Think of them reading it for the 50th time. Do you think
they will still appreciate your little history lesson?


> You are concentrating on the detail of what I wrote. I don't care what
> the eventual wording is (and for sure, someone else is far more
> qualified than me to suggest wording that is better for a beginner). My
> point is simply that the error _could_ contain _some_ more information
> that addresses this issue for a beginner who may be typing in Py2
> examples that encourages them to seek out Py3 tutorials instead.

Of course it could. It could also include a link to the Python documentation, a
history of how and why Python 3000 came to be, and a note that if you email the
Python Software Foundation they'll pay you $50, and none of these things will
make the slightest difference if people don't read them.

It's not a question of what the error message *could* say, its what it *should*
say, and more is not always better.

I think that there are broadly two sets of newbies in the world:

- those who will read the message, and be able to resolve the problem from the
current wording ("oh, it needs parentheses, like a function");

- and those who won't, in which case adding more words to the message won't help
in the slightest.


>> That's why I asked Ben if there was something we
>> could do to make the sentence clearer.
> 
> Exactly. Ben is an example of someone more qualified than me to suggest
> the correct words.

And is typical, Ben has not (as far as I can see) replied. Which I take as an
answer to my question: no, he did not read the error message, or spend more
than a millisecond trying to understand it, and adding more words wouldn't have
changed that in the slightest.

"Cynical" is what Pollyannas call realists :-)



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Create a list of dates for same day of week in a year

2017-06-27 Thread Sayth Renshaw
Afternoon

Is there an obvious method I am missing in creating a list of dates? I want to 
get a list of each Saturday and each Wednesday for the year 2017.

It seems and maybe this is where I am wrong but doesn't the datetime library 
already know the dates if yes is there an easy way to query it?

Also checked out Python Arrow http://arrow.readthedocs.io/en/latest/ as it 
expands on the python standard library but I couldn't find an obvious example 
of this.

Thoughts or examples?

Cheers

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


Re: Create a list of dates for same day of week in a year

2017-06-27 Thread Chris Angelico
On Wed, Jun 28, 2017 at 12:48 PM, Sayth Renshaw  wrote:
> Is there an obvious method I am missing in creating a list of dates? I want 
> to get a list of each Saturday and each Wednesday for the year 2017.
>
> It seems and maybe this is where I am wrong but doesn't the datetime library 
> already know the dates if yes is there an easy way to query it?
>

Sorta-kinda.

>>> import datetime
>>> today = datetime.date.today()
>>> monday = today - datetime.timedelta(days=today.weekday())
>>> wednesday = monday + datetime.timedelta(days=2)
>>> saturday = monday + datetime.timedelta(days=5)
>>> week = datetime.timedelta(days=7)
>>> next_wed = wednesday + week

You can mess around with that. If you want to find the beginning of
the year, you could start by using datetime.date(2017, 1, 1) instead
of today(), and then locate the previous Monday the same way.

So yes, all the information is available, but no, there's no easy way
to say "give me all the Saturdays in 2017". You'd have to iterate.

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


Re: How to build a simple neural network in 9 lines of Python code

2017-06-27 Thread Ian Kelly
On Tuesday, June 27, 2017, Steve D'Aprano 
wrote:

> On Wed, 28 Jun 2017 02:23 am, Sam Chats wrote:
>
> >
> https://medium.com/technology-invention-and-more/how-to-
> build-a-simple-neural-network-in-9-lines-of-python-code-cc8f23647ca1
>
>
> The derivative of the sigmoid curve given is completely wrong.
>
> def __sigmoid(self, x):
> return 1 / (1 + exp(-x))
>
> def __sigmoid_derivative(self, x):
> return x * (1 - x)
>
>
> Should be:
>
> def __sigmoid_derivative(self, x):
> return exp(x) / (1 + exp(x))**2
>
>
>
> http://mathworld.wolfram.com/SigmoidFunction.html
>
>
Actually, it's not stated clearly but x is not the same in each function.
The return value of sigmoid is the input of sigmoid_derivative. The article
that you linked confirms that this identity holds.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to build a simple neural network in 9 lines of Python code

2017-06-27 Thread Chris Angelico
On Wed, Jun 28, 2017 at 12:28 PM, Steve D'Aprano
 wrote:
> E.g. comparing Python to AcmeScript, where you write:
>
>
> program myprogram
> begin program
> load library webbrowser
> new string url copied from 'http://www.example.com'
> with webbrowser
>   begin
> method = open
> method.call url
>   end
> end program
>
> (I made that language up, for the record, don't bother googling for it.)

Just to be contrary, I did. And Google suggested that maybe I meant
"acnescript".

H.

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


Re: Syntax error for simple script

2017-06-27 Thread Chris Angelico
On Wed, Jun 28, 2017 at 12:46 PM, Steve D'Aprano
 wrote:
> I think that there are broadly two sets of newbies in the world:
>
> - those who will read the message, and be able to resolve the problem from the
> current wording ("oh, it needs parentheses, like a function");
>
> - and those who won't, in which case adding more words to the message won't 
> help
> in the slightest.

And in between are the people who read the message but don't
understand it, and then key it into a web search engine. For those
people, the value isn't necessarily in the clarity of the wording, but
in the specificity of it; as long as Google/DuckDuckGo/Bing/Yahoo can
find the right information given that error as input, it's good
enough. As such, I think the current wording is excellent; I start
typing "missing parentheses" and all four of those search engines
suggest the rest of the message, and all of them have good results
(mainly from Stack Overflow) at the top of the search. Bing and DDG
even pick up part of the answer to show above the results, with DDG
edging out Bing in usefulness.

Or maybe they're a subcategory of the first group. I don't know. In
any case, consistency helps the search engines (it's easier to search
for "missing parentheses in call to print" than for "unexpected error
at <0x13456474678fbcea>" where the hex number varies according to
cause), and brevity (as long as clarity isn't sacrificed) is a huge
advantage in getting the message typed in.

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


Re: How to build a simple neural network in 9 lines of Python code

2017-06-27 Thread Rustom Mody
On Wednesday, June 28, 2017 at 1:04:46 AM UTC+5:30, Marko Rauhamaa wrote:
> John Ladasky 
> > OK, that's cheating a bit, using Numpy. It's a nice little program,
> > but it leverages a huge, powerful library.
> 
> What would *not* be cheating? A language without a library would be
> dead.

One man's powerful is another's simple
A beginning C programmer treats lists as a "data structure" for an advanced
course on data structures
A beginning python programmer starts using them in his first hour or at worst 
day

Likewise python does this with the help of numpy
>From which one could conclude one of
- This (numpy-using) 9 lines is advanced
- Numpy needs to be in python's core

My guess of Marko's intent of bringing up APL is just to show a language in
which numpy is effectively in the language core

My other guess is that these same 9 lines could be translated to R with no 
import

PS I am not advocating numpybuiltintopython
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Create a list of dates for same day of week in a year

2017-06-27 Thread Sayth Renshaw

> > Is there an obvious method I am missing in creating a list of dates? I want 
> > to get a list of each Saturday and each Wednesday for the year 2017.
> >
> > It seems and maybe this is where I am wrong but doesn't the datetime 
> > library already know the dates if yes is there an easy way to query it?
> >
> 
> Sorta-kinda.
> 
> >>> import datetime
> >>> today = datetime.date.today()
> >>> monday = today - datetime.timedelta(days=today.weekday())
> >>> wednesday = monday + datetime.timedelta(days=2)
> >>> saturday = monday + datetime.timedelta(days=5)
> >>> week = datetime.timedelta(days=7)
> >>> next_wed = wednesday + week
> 
> You can mess around with that. If you want to find the beginning of
> the year, you could start by using datetime.date(2017, 1, 1) instead
> of today(), and then locate the previous Monday the same way.
> 
> So yes, all the information is available, but no, there's no easy way
> to say "give me all the Saturdays in 2017". You'd have to iterate.
> 
> ChrisA

Thanks ChrisA could using the calendar and a for loop work better?

As below test a date to see if the value = 5 so loop months 1-12 and then days 
1-31 and just throw an error when the date doesn't exist 30th of Feb etc
In [19]: import calendar


In [23]: calendar.weekday(2017,6,24)
Out[23]: 5

Or I have set the Saturday to be the firstday of the week 
https://docs.python.org/2/library/calendar.html is there a way to loop for all 
firstdayofweeks in year and return dates out that way?

Not sure how to get all dates in the year as an object for iteration though. 
The calendar iter items end at months 
https://docs.python.org/2/library/calendar.html#calendar.Calendar.itermonthdays

In [20]: calendar.setfirstweekday(calendar.SATURDAY)

In [21]: calendar.firstweekday()
Out[21]: 5

Cheers

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


Re: Create a list of dates for same day of week in a year

2017-06-27 Thread waldemar . osuch

> Thoughts or examples?
> 
dateutil.rrule is what you may use e.g.


In [38]: from dateutil import rrule 

In [39]: from datetime import date  

In [40]: end = date(2017, 12, 31)   

In [41]: rr = rrule.rrule(rrule.WEEKLY, byweekday=[0, 2], until=end)

In [42]: days = list(rr)

In [43]: len(days)  
Out[43]: 53 

In [44]: days[:5], days[-5:]
Out[44]:
([datetime.datetime(2017, 6, 28, 23, 58, 11),   
  datetime.datetime(2017, 7, 3, 23, 58, 11),
  datetime.datetime(2017, 7, 5, 23, 58, 11),
  datetime.datetime(2017, 7, 10, 23, 58, 11),   
  datetime.datetime(2017, 7, 12, 23, 58, 11)],  
 [datetime.datetime(2017, 12, 13, 23, 58, 11),  
  datetime.datetime(2017, 12, 18, 23, 58, 11),  
  datetime.datetime(2017, 12, 20, 23, 58, 11),  
  datetime.datetime(2017, 12, 25, 23, 58, 11),  
  datetime.datetime(2017, 12, 27, 23, 58, 11)]) 

In [45]:

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


Combining 2 data series into one

2017-06-27 Thread Bhaskar Dhariyal
Hi!

I have 2 dataframe i.e. df1['first_name'] and df2['last_name']. I want to make 
it as df['name']. How to do it using pandas dataframe.

first_name
--
bhaskar
Rohit


last_name
---
dhariyal
Gavval

should appear as

name
--
bhaskar dhariyal
Rohit Gavval



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