Re: >>> %matplotlib inline results in SyntaxError: invalid syntax

2016-01-29 Thread Steven D'Aprano
On Fri, 29 Jan 2016 06:04 pm, Mike S wrote:

> %matplotlib inline
> 
> I get an error on the last line. I am running this code in Idle Python
> 3.4.4 Shell...
> 
> Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32
> bit (Intel)] on win32
> Type "copyright", "credits" or "license()" for more information.
>  >>> import numpy as np
>  >>> import pandas as pd
>  >>> import random
>  >>> import matplotlib.pyplot as plt
>  >>> %matplotlib inline
> SyntaxError: invalid syntax
> 
> What am I doing wrong? Suggested reading?

That %matplotlib looks to me like iPython "magic" -- yes, that's the
official name for it. It's not real Python code, and won't run in a regular
Python interpreter like IDLE.

IPython is a custom Python interactive interpreter. As well as running
regular Python code, it includes special syntax for magic such as:

%cd
%run
%bg

and many more. 

http://ipython.org/ipython-doc/rel-0.10.2/html/interactive/reference.html#magic

You could try installing iPython and running the tutorial examples in that,
or perhaps finding a better tutorial that actually bothers to mention what
it needs to run.

(You have read the tutorial from the beginning, yes?)




-- 
Steven

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


Re: >>> %matplotlib inline results in SyntaxError: invalid syntax

2016-01-29 Thread Mike S via Python-list

On 1/28/2016 11:57 PM, Steven D'Aprano wrote:

On Fri, 29 Jan 2016 06:04 pm, Mike S wrote:


%matplotlib inline

I get an error on the last line. I am running this code in Idle Python
3.4.4 Shell...

Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32
bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
  >>> import numpy as np
  >>> import pandas as pd
  >>> import random
  >>> import matplotlib.pyplot as plt
  >>> %matplotlib inline
SyntaxError: invalid syntax

What am I doing wrong? Suggested reading?


That %matplotlib looks to me like iPython "magic" -- yes, that's the
official name for it. It's not real Python code, and won't run in a regular
Python interpreter like IDLE.

IPython is a custom Python interactive interpreter. As well as running
regular Python code, it includes special syntax for magic such as:

%cd
%run
%bg

and many more.

http://ipython.org/ipython-doc/rel-0.10.2/html/interactive/reference.html#magic

You could try installing iPython and running the tutorial examples in that,
or perhaps finding a better tutorial that actually bothers to mention what
it needs to run.

(You have read the tutorial from the beginning, yes?)


Thank you Chris and Steven, I'll see if I can get iPython running and do 
a tutorial.


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


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Jussi Piitulainen
Fillmore writes:

> Does Python have Regexps?

Start by importing the re module (as said). Find its documentation at
the following link (together with a list of many other modules that come
standard with Python). Also, once imported to the interactive session,
help(re), dir(re).

https://docs.python.org/3/library/index.html

But there's an alternative implementation, which should be easy to
install (worked for me when I needed it), called regex. Find it at the
following link and see for yourself.

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


Error message

2016-01-29 Thread Emeka Ikele
Please I downloaded Python 3.5 (32 bit)  for Windows software. I installed
it but it keeps giving me an error message that a file was not found and I
should please re-install to fix the problem. I've tried that severally but
to no avail. Please what can I do or should I just install the 2.7 version?
Thank you
-- 
https://mail.python.org/mailman/listinfo/python-list


Getting VS2015 to work with arcpy

2016-01-29 Thread Paul Schrum
I have posted this question on stackoverflow, but I think I may be more
likely to get help in the mailing list:

http://stackoverflow.com/questions/35069640/getting-vs2015-to-work-with-arcpy

Getting VS2015 to work with arcpy

I am taking a course on programming ESRI's ArcGIS using Python. Although
the course content shows us how to work with various IDE's, I would like to
do my homework in Visual Studio 2015 (Community Edition). But I am having
trouble getting it to work on my laptop and would like some advice.

I have successfully installed ArcGIS. I have successfully run some Python
scripts which include the use of the arcpy module. One IDE that recognizes
arcpy, pycharm, shows me path information about the environment. For
example, PyCharm's External Libraries window shows C:\Python27\ArcGIS10.3 .

In Visual Studio, when I open a .py file known to run under the other
interpreters, the IDE marks import arcpy as an unknown package. So in
Visual Studio I am attempting to set up a new Python Enviornment,
"ArcGIS-enabled", to get it to recognize that package. So far I have not
been successful. Here I what I have tried so far:

I set

Prefix Path = C:\Python27\ArcGIS10.3\Interpreter Path =
C:\Python27\ArcGIS10.3\python.exeWindowed Interpreter =
C:\Python27\ArcGIS10.3\pythonw.exeLibrary Path =
C:\Python27\ArcGIS10.3\lib

Can someone please help me figure this out?
-- 
https://mail.python.org/mailman/listinfo/python-list


>>> %matplotlib inline results in SyntaxError: invalid syntax

2016-01-29 Thread Mike S via Python-list
I have installed Python 3.4.4 on XPSP3 and am trying to work my way 
through this tutorial.


A Complete Tutorial on Ridge and Lasso Regression in Python
http://www.analyticsvidhya.com/blog/2016/01/complete-tutorial-ridge-lasso-regression-python/

In Step 2 "Why Penalize the Magnitude of Coefficients?" we are shown 
this code:


#Importing libraries. The same will be used throughout the article.
import numpy as np
import pandas as pd
import random
import matplotlib.pyplot as plt
%matplotlib inline

I get an error on the last line. I am running this code in Idle Python 
3.4.4 Shell...


Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 
bit (Intel)] on win32

Type "copyright", "credits" or "license()" for more information.
>>> import numpy as np
>>> import pandas as pd
>>> import random
>>> import matplotlib.pyplot as plt
>>> %matplotlib inline
SyntaxError: invalid syntax

What am I doing wrong? Suggested reading?
TIA,
Mike
--
https://mail.python.org/mailman/listinfo/python-list


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Ulli Horlacher
Steven D'Aprano  wrote:

> Every time I make a half-hearted attempt to learn enough Perl syntax to get
> started, I keep running into the differences between $foo, %foo and @foo
> and dire warnings about what happens if you use the wrong sigil

I have started learning Python several times and surrendered because my
brain was too Perl hardcoded after 30 years, but NOW I was successful :-)
(I still find Perl syntax better...)

About the variables in short:

$foo is a scalar (number, string, reference, file handle)
@foo is an array
%foo is a hash (dictionary in Python slang)

and yes, you can use them all together in same code, they are different.

For more discussion about Perl syntax one should better go to
comp.lang.perl

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: [email protected]
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Chris Angelico
On Fri, Jan 29, 2016 at 6:12 PM, Steven D'Aprano  wrote:
> On Fri, 29 Jan 2016 11:25 am, Chris Angelico wrote:
>
>> Probably the biggest thing to take note of is the Python object model
>> - how names and objects and assignment work. It's pretty
>> straight-forward, but if it's not what you're used to, you'll need to
>> get your head around it. Here's a good talk on the subject:
>>
>> http://nedbatchelder.com/text/names1.html
>
>
> Every time I make a half-hearted attempt to learn enough Perl syntax to get
> started, I keep running into the differences between $foo, %foo and @foo
> and dire warnings about what happens if you use the wrong sigil, and then I
> get confused. Is there a good discussion of how names and references work
> in Perl, equivalent to Ned's discussion?

Ooh. Good point. I'd like to see one of those too.

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


[ANN] Gajja 0.1: Fake objects for real tests

2016-01-29 Thread Ben Finney
Howdy all,

I am pleased to announce the first release of the testing library I've
named Gajja https://pypi.python.org/pypi/gajja/>.

Its purpose is to allow fine-grained control of not only file content,
but metadata and system access behaviour, for in-memory test doubles.

Currently it provides classes of test doubles for filesystem entries and
subprocesses; and a framework for hooking them into individual test
cases or test case classes.

Each wrapped system interface will respond specifically for the
identifier (filesystem path, or subprocess command line) of that
specific double. Any other call to the same system interface will be
passed through to the real function; only access to the test double
should behave differently.

At the moment the documentation consists of a ‘doc/tutorial.txt’ giving
a worked example of doubling a filesystem entry to report the test
double's file size from `os.stat` (and not affect `os.stat` for any
other file).

Please contact me at  if you have feedback
on this, or report an issue at the project's homepage
https://notabug.org/bignose/python-gajja>.

Discussion here in the Python forum is also welcome.

-- 
 \ “Facts are stubborn things; and whatever may be our wishes, our |
  `\   inclinations, or the dictates of our passion, they cannot alter |
_o__)the state of facts and evidence.” —John Adams, 1770-12-04 |
Ben Finney

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


Re: Question about asyncio and blocking operations

2016-01-29 Thread Maxime Steisel
Le 28 janv. 2016 22:52, "Ian Kelly"  a écrit :
>
> On Thu, Jan 28, 2016 at 2:23 PM, Maxime S  wrote:
> >
> > 2016-01-28 17:53 GMT+01:00 Ian Kelly :
> >>
> >> On Thu, Jan 28, 2016 at 9:40 AM, Frank Millman 
wrote:
> >>
> >> > The caller requests some data from the database like this.
> >> >
> >> >return_queue = asyncio.Queue()
> >> >sql = 'SELECT ...'
> >> >request_queue.put((return_queue, sql))
> >>
> >> Note that since this is a queue.Queue, the put call has the potential
> >> to block your entire event loop.
> >>
> >
> > Actually, I don't think you actually need an asyncio.Queue.
> >
> > You could use a simple deque as a buffer, and call fetchmany() when it
is
> > empty, like that (untested):
>
> True. The asyncio Queue is really just a wrapper around a deque with
> an interface designed for use with the producer-consumer pattern. If
> the producer isn't a coroutine then it may not be appropriate.
>
> This seems like a nice suggestion. Caution is advised if multiple
> cursor methods are executed concurrently since they would be in
> different threads and the underlying cursor may not be thread-safe.
> --
> https://mail.python.org/mailman/listinfo/python-list

Indeed, the run_in_executor call should probably protected by an
asyncio.Lock.

But it is a pretty strange idea to call two fetch*() method concurrently
anyways.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about asyncio and blocking operations

2016-01-29 Thread Frank Millman

"Frank Millman"  wrote in message news:[email protected]...

I have read the other messages, and I can see that there are some clever 
ideas there. However, having found something that seems to work and that I 
feel comfortable with, I plan to run with this for the time being.


A quick update.

Now that I am starting to understand this a bit better, I found it very easy 
to turn my concept into an Asynchronous Iterator.


class AsyncCursor:
   def __init__(self, loop, sql):
   self.return_queue = asyncio.Queue()
   request_queue.put((self.return_queue, loop, sql))

   async def __aiter__(self):
   return self

   async def __anext__(self):
   row = await self.return_queue.get()
   if row is not None:
   return row
   else:
   self.return_queue.task_done()
   raise StopAsyncIteration

The caller can use it like this -

   sql = 'SELECT ...'
   cur = AsyncCursor(loop, sql)
   async for row in cur:
   print('got', row)

Frank


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


Re: show instant data on webpage

2016-01-29 Thread mustang



Then I'd use gnuplot or matplotlib.


ok, but then I can upload/plot them online?
--
https://mail.python.org/mailman/listinfo/python-list


Pyhon Icon

2016-01-29 Thread Walter Nakatana
Good day,

Every time I install python , I don't see the icon on my desktop neither in my 
C: drive


Have a great day

Kind Regards,


Walter Nakatana
IT Help-Desk Administrator
Meat Corporation of Namibia, MEATCO
Tel : +264 (0)61 321 6459
Fax : +264 (0)61 321 6401
Mobile : +264 (0)81 744 7474
E-mail: [email protected]
Web: www.meatco.com.na
[MeatCo Email Logo]

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


Re: psss...I want to move from Perl to Python

2016-01-29 Thread James Harris

On 29/01/2016 09:12, Ulli Horlacher wrote:

Steven D'Aprano  wrote:


Every time I make a half-hearted attempt to learn enough Perl syntax to get
started, I keep running into the differences between $foo, %foo and @foo
and dire warnings about what happens if you use the wrong sigil


I have started learning Python several times and surrendered because my
brain was too Perl hardcoded after 30 years, but NOW I was successful :-)


I nearly gave up with Python at the very beginning before I realised not 
to mix tabs and spaces.



(I still find Perl syntax better...)


Perl may be easier to 'think in' for those who are familiar with it. 
Perl syntax is shorter. And expressions have fewer elements as some 
operands are implied.


Python's constructions are more explicit, making the effect more 
apparent in the source.



About the variables in short:

$foo is a scalar (number, string, reference, file handle)
@foo is an array
%foo is a hash (dictionary in Python slang)

and yes, you can use them all together in same code, they are different.


IIRC it's not quite that simple in that the type depends on the context 
that Perl thinks is current. I won't go into detail as this is not a 
Perl group but I found Perl horrible to work with. It is slick but also 
cryptic.


James

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


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Steven D'Aprano
On Fri, 29 Jan 2016 11:21 pm, Ulli Horlacher wrote:

> Most tutorials I found so far makes OO mandatory.


You should have started with the official tutorial:

https://docs.python.org/2/tutorial/


which doesn't get into classes until Chapter 9, after:

- using Python as a calculator;
- numbers, strings, unicode, lists;
- if, for, the range function;
- defining functions;
- stacks, queues;
- functional programming;
- list comprehensions;
- tuples, sets, dicts;
- modules;
- string formatting, reading and writing files, json; and
- exceptions

It's notable that *functional programming* is introduced before classes.



-- 
Steven

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


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Ulli Horlacher
James Harris  wrote:

> I nearly gave up with Python at the very beginning before I realised not 
> to mix tabs and spaces.

I nearly gave up with Python at the very beginning before I realised that
OO-programming is optional in Python! :-)

Most tutorials I found so far makes OO mandatory.

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: [email protected]
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: show instant data on webpage

2016-01-29 Thread Joel Goldstick
On Fri, Jan 29, 2016 at 6:48 AM, mustang  wrote:

>
> Then I'd use gnuplot or matplotlib.
>>
>> ok, but then I can upload/plot them online?
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Confusing mustang.  You said:

anyway I'm not interested in building website I've only to plot/show data
collecting them from a sensor and plot them in a realtime graph (for
example temperature).

and then you said:

ok, but then I can upload/plot them online?

So, the python plotting packages mentioned can create files that hold your
graphs.  As to whether you want to display them on the web or send them
around as attachments to your coworkers, or build some local application to
display them is your choice

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


Python 3.5.1

2016-01-29 Thread Joel Cotto
Hi,

I'm using the new release of python ver 3.5.1 but i got problem using its
code to communicate w/ serial port. I'm receiving port error. Hope you can
guide me if there are change made in the command. Thanks and Good Day

import serial ser = 0 def init_serial(): COMNUM = 1 global ser ser =
serial.Serial() ser.baudrate = 9600 ser.port = COMNUM - 1 ser.timeout = 10
ser.isOpen() if ser.isOpen(): print ('Open: ' + ser.portstr) init_serial()
temp = input('Enter SCL command, hit enter:\r\n') ser.write(temp) while 1:
bytes = ser.readline() print ('You sent: ' + bytes)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pyhon Icon

2016-01-29 Thread Joel Goldstick
On Fri, Jan 29, 2016 at 6:00 AM, Walter Nakatana 
wrote:

> Good day,
>
> Every time I install python , I don't see the icon on my desktop neither
> in my C: drive
>
>
> Try searching the list.  There are dozens of questions and answers about
installing python on windows.  Failing that,
be specific -- What OS.  Where did you get python.  What procedure did you
use?  Can you enter the python shell when you are at a command prompt?



> Have a great day
>
> Kind Regards,
>
>
> Walter Nakatana
> IT Help-Desk Administrator
> Meat Corporation of Namibia, MEATCO
> Tel : +264 (0)61 321 6459
> Fax : +264 (0)61 321 6401
> Mobile : +264 (0)81 744 7474
> E-mail: [email protected]
> Web: www.meatco.com.na
> [MeatCo Email Logo]
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



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


Re: Python 3.5.1

2016-01-29 Thread Joel Goldstick
On Fri, Jan 29, 2016 at 10:35 AM, Joel Cotto  wrote:

> Hi,
>
> I'm using the new release of python ver 3.5.1 but i got problem using its
> code to communicate w/ serial port. I'm receiving port error. Hope you can
> guide me if there are change made in the command. Thanks and Good Day
>
> import serial ser = 0 def init_serial(): COMNUM = 1 global ser ser =
> serial.Serial() ser.baudrate = 9600 ser.port = COMNUM - 1 ser.timeout = 10
> ser.isOpen() if ser.isOpen(): print ('Open: ' + ser.portstr) init_serial()
> temp = input('Enter SCL command, hit enter:\r\n') ser.write(temp) while 1:
> bytes = ser.readline() print ('You sent: ' + bytes)
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Welcome.  Please repost using plain text so that your indentation is
correct.  Your code is unreadable as is

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


Re: Pyhon Icon

2016-01-29 Thread Oscar Benjamin
On 29 January 2016 at 11:00, Walter Nakatana  wrote:
> Every time I install python , I don't see the icon on my desktop neither in 
> my C: drive

Hi Walter, I guess you're using Windows. There are many different ways
to run Python. One way that beginners often use is to run IDLE. You
can find some instructions for that here:
http://www.annedawson.net/Python_Editor_IDLE.htm

The exact instructions will depend on which version of Windows you are
using, which version of Python you installed and exactly how you
installed it. You haven't given that information but I would guess
that you have IDLE installed and that you can run it from the programs
menu somehow.

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


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Random832
On Fri, Jan 29, 2016, at 04:12, Ulli Horlacher wrote:
> Steven D'Aprano  wrote:
> 
> > Every time I make a half-hearted attempt to learn enough Perl syntax to get
> > started, I keep running into the differences between $foo, %foo and @foo
> > and dire warnings about what happens if you use the wrong sigil
...
> $foo is a scalar (number, string, reference, file handle)
> @foo is an array
> %foo is a hash (dictionary in Python slang)
> 
> and yes, you can use them all together in same code, they are different.

The main source of confusion is that $foo[5] is an element of @foo.
$foo{'x'} is an element of %foo. Both of these have absolutely nothing
to do with $foo.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Sven R. Kunze

Hi,

On 29.01.2016 01:01, Fillmore wrote:

I look and Python and it looks so much more clean

add to that that it is the language of choice of data miners...

add to that that iNotebook looks powerful



All true. :)


Does Python have Regexps?


"import re"

https://docs.python.org/3.5/library/re.html

How was the Python 2.7 vs Python 3.X solved? which version should I go 
for?


Python 3 is the new and better one.

(I for one can see we already use all __future__ imports to get as close 
as possible to Python 3 in our production code)



Do you think that switching to Python from Perl is a good idea at 45?



http://srkunze.blogspot.de/2016/01/next-programming-language.html


Where do I get started moving from Perl to Python?


some keywords:

basic mathematical calculations
dicts and lists
classes
closures/mixins

and other tutorials. :)


which gotchas need I be aware of?


Don't worry. Just try it out. :)

Best,
Sven

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


Re: Error message

2016-01-29 Thread Oscar Benjamin
On 28 January 2016 at 18:51, Emeka Ikele  wrote:
> Please I downloaded Python 3.5 (32 bit)  for Windows software. I installed
> it but it keeps giving me an error message that a file was not found and I
> should please re-install to fix the problem. I've tried that severally but
> to no avail. Please what can I do or should I just install the 2.7 version?

What does the error message say exactly? Which file is missing?

Just guessing but is it complaining about a file called
"api-ms-win-crt-runtime-l1-1-0.dll"? If so then you need to install
this file in an update from Microsoft here:
https://support.microsoft.com/en-us/kb/2999226

Afterwards you should be able to install Python 3.5. Alternatively you
can install Python 3.4 which does not need this dll.

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


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Fillmore

So many answers. So much wisdom...thank you everyone

On 01/28/2016 07:01 PM, Fillmore wrote:




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


The computer that mastered Go

2016-01-29 Thread Seymore4Head
https://www.youtube.com/watch?v=g-dKXOlsf98
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Fillmore


+1

On 1/29/2016 10:07 AM, Random832 wrote:


The main source of confusion is that $foo[5] is an element of @foo.
$foo{'x'} is an element of %foo. Both of these have absolutely nothing
to do with $foo.



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


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Fillmore


I actually have a few followup question.

- will iNotebook also work in Python 3?

- What version of Python 3 do you recommend I install on Windows?

- Is Python 3 available also for CygWin?

- I use Ubuntu at home. Will I be able to install Python 3 with apt-get? 
will I need to uninstall previous versions?


- Is there a good IDE that can be used for debugging? all free IDEs for 
Perl suck and it would be awesome if Python was better than that.


Thanks


On 1/28/2016 7:01 PM, Fillmore wrote:


I learned myself Perl as a scripting language over two decades ago. All


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


Re: The computer that mastered Go

2016-01-29 Thread mm0fmf via Python-list

On 29/01/2016 19:46, Seymore4Head wrote:

https://www.youtube.com/watch?v=g-dKXOlsf98



Is it written in Python?
--
https://mail.python.org/mailman/listinfo/python-list


Re: psss...I want to move from Perl to Python

2016-01-29 Thread sohcahtoa82
On Thursday, January 28, 2016 at 6:34:34 PM UTC-8, Chris Angelico wrote:
> On Fri, Jan 29, 2016 at 1:06 PM, Paul Rubin  wrote:
> > Fillmore  writes:
> >> I look and Python and it looks so much more clean
> >
> > Yes it is, I forgot everything I knew about Perl shortly after starting
> > to use Python.
> 
> https://xkcd.com/353/
> 
> Particularly the hover text. :)
> 
> ChrisA

I have this comic pinned to the outside wall of my cubicle at work, where I use 
Python for 98% of my work.

It's funny...when I first started using Python, I hated it because it held your 
hand and made everything too easy.  I was a major C, C++ and Java fanatic.  
Now, I LOVE Python because it holds your hand and makes everything so easy.

I still like C and C++, but have basically learned that each language has it's 
place.  I wouldn't try to write a AAA-quality game in Python, just like I 
wouldn't write something that should be a simple 50-line Python script in C++.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: psss...I want to move from Perl to Python

2016-01-29 Thread sohcahtoa82
On Friday, January 29, 2016 at 1:12:34 AM UTC-8, Ulli Horlacher wrote:
> Steven D'Aprano  wrote:
> 
> > Every time I make a half-hearted attempt to learn enough Perl syntax to get
> > started, I keep running into the differences between $foo, %foo and @foo
> > and dire warnings about what happens if you use the wrong sigil
> 
> I have started learning Python several times and surrendered because my
> brain was too Perl hardcoded after 30 years, but NOW I was successful :-)
> (I still find Perl syntax better...)
> 
> About the variables in short:
> 
> $foo is a scalar (number, string, reference, file handle)
> @foo is an array
> %foo is a hash (dictionary in Python slang)
> 
> and yes, you can use them all together in same code, they are different.
> 
> For more discussion about Perl syntax one should better go to
> comp.lang.perl
> 
> -- 
> Ullrich Horlacher  Server und Virtualisierung
> Rechenzentrum IZUS/TIK E-Mail: [email protected]
> Universitaet Stuttgart Tel:++49-711-68565868
> Allmandring 30aFax:++49-711-682357
> 70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/

"(I still find Perl syntax better...)"

I'm convinced that anyone who actually prefers Perl's syntax over Python is 
suffering from Stockholm Syndrome.

People frequently joke about Perl being "write-only code" due to how frequently 
people will write code, not look at it for a week or so, then come back to it 
and not be able to understand what the code is doing without excessive 
comments.  Or they will say that Perl code is indistinguishable from line noise.

*These are not the hallmarks of a good syntax*

Readability counts.  I'd say readability is one of the most important features 
of a language, as you will read your code far more than you write it.  Perl is 
not readable.  I don't care how powerful your language is if you can't read it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Chris Angelico
On Sat, Jan 30, 2016 at 7:42 AM, Fillmore  wrote:
> I actually have a few followup question.
>
> - will iNotebook also work in Python 3?

You mean the IPython notebook? Yep!

> - What version of Python 3 do you recommend I install on Windows?

The latest stable - currently, that's 3.5.

> - Is Python 3 available also for CygWin?

I'l let someone else answer that.

> - I use Ubuntu at home. Will I be able to install Python 3 with apt-get?
> will I need to uninstall previous versions?

You should be able to simply "apt-get install python3" and get
whichever release your Ubuntu is shipping. It might be 3.4 or 3.3, but
it's unlikely to be older than that.

> - Is there a good IDE that can be used for debugging? all free IDEs for Perl
> suck and it would be awesome if Python was better than that.
>

Debugging Python code is generally easy enough without an IDE; any
time something goes wrong, you get an exception with a very pretty
traceback. That's usually enough on its own. A little bit of editor
integration can help you jump to the lines mentioned, in the same way
that you might get that with C compiler errors; that's all I've ever
needed.

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


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Rick Johnson
On Friday, January 29, 2016 at 6:21:21 AM UTC-6, Ulli Horlacher wrote:
> I nearly gave up with Python at the very beginning before
> I realised that OO-programming is optional in Python! :-)
> Most tutorials I found so far makes OO mandatory.

Just more evidence that old dogs are incapable of learning
new tricks. Either learn how to wield Neuroplasticity to
your advantage, or go curl up into a ball and wait for death
to come. People who are unwilling to "expanding their
intellectual horizons" make me sick!!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Nathan Hilterbrand
On Fri, Jan 29, 2016 at 3:42 PM, Fillmore 
wrote:

>
> I actually have a few followup question.
>
> - will iNotebook also work in Python 3?
>
> - What version of Python 3 do you recommend I install on Windows?
>
> - Is Python 3 available also for CygWin?
>
> - I use Ubuntu at home. Will I be able to install Python 3 with apt-get?
> will I need to uninstall previous versions?
>
> - Is there a good IDE that can be used for debugging? all free IDEs for
> Perl suck and it would be awesome if Python was better than that.
>
> Thanks
>
>
>
> On 1/28/2016 7:01 PM, Fillmore wrote:
>
>>
>> I learned myself Perl as a scripting language over two decades ago. All
>>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Yes, python3 is available for cygwin.  My cygwin (fairly current) has
python 3.4.3 installed

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


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Gregory Ewing

Random832 wrote:

The main source of confusion is that $foo[5] is an element of @foo.
$foo{'x'} is an element of %foo. Both of these have absolutely nothing
to do with $foo.


And this is where Perl seems totally insane to me. Obviously
it knows from the square brackets that foo[5] is referring
to the array called foo rather than the scalar called foo
or the hash called foo. So what purpose do the sigils serve,
other than provide you with the opportunity to use the
wrong one?

I know there's probably an answer to that question, but
the point is that it *looks* screwy to someone coming from
any other language on the planet.

I'm glad I learned Python first so I didn't have to
unlearn stuff like that. Was it Dijkstra who complained
about students whose minds had been damaged by BASIC?
Perl damage must be ten times worse...

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


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Ben Finney
"Sven R. Kunze"  writes:

> On 29.01.2016 01:01, Fillmore wrote:
> > How was the Python 2.7 vs Python 3.X solved? which version should I
> > go for?
>
> Python 3 is the new and better one.

More importantly: Python 2 will never improve; Python 3 is the only one
that is actively developed.

-- 
 \   “We spend the first twelve months of our children's lives |
  `\  teaching them to walk and talk and the next twelve years |
_o__)   telling them to sit down and shut up.” —Phyllis Diller |
Ben Finney

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


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Chris Angelico
On Sat, Jan 30, 2016 at 7:41 AM,   wrote:
> It's funny...when I first started using Python, I hated it because it held 
> your hand and made everything too easy.  I was a major C, C++ and Java 
> fanatic.  Now, I LOVE Python because it holds your hand and makes everything 
> so easy.
>

Exactly.

> I still like C and C++, but have basically learned that each language has 
> it's place.  I wouldn't try to write a AAA-quality game in Python, just like 
> I wouldn't write something that should be a simple 50-line Python script in 
> C++.
>

And you'd be amazed at how many of the things people say "oh, you
can't do *that* in Python" can actually be done 99% in Python and 1%
in some other language - often with the 1% being a standard library.
Sure, Python's arithmetic operations aren't fast enough to do heavy
computational work in - but what if you just deploy numpy and let
Fortran do the heavy lifting? You can write your application logic in
Python, and get the performance of Fortran.

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


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Cody Piersall
On Fri, Jan 29, 2016 at 2:42 PM, Fillmore 
wrote:
> I actually have a few followup question.

> - will iNotebook also work in Python 3?
Yes!  And just FYI, it's called they Jupyter Notebook now, but pretty much
everyone still (colloquially) calls it the IPython Notebook so you're in
good company.  When you're searching online, you should search for Jupyter
though, or you might get obsolete docs.

> - What version of Python 3 do you recommend I install on Windows?
Might as well go for Python 3.5.

> [snip questions I don't know the answer to]
> - Is there a good IDE that can be used for debugging? all free IDEs for
Perl suck and it would be awesome if Python was better than that.
PyCharm is a really good IDE.  You can use the community edition for free
as long as it's for open source projects or your company makes less than $1
million a year.  For bigger projects I use PyCharm, but it's not bad to use
just a plain text editor either.  If your company is making $1 million a
year, presumably they can afford the license fees.  Download link:
https://www.jetbrains.com/pycharm/download/

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


Font issues Tkinter/Python 3.5

2016-01-29 Thread KP
import tkinter as tk
from tkinter import ttk
from tkinter import font
...
def __init__(self):
self.root = tk.Tk()
self.root.title('Main Window')
self.root.geometry('1000x800+200+200')
self.root.minsize(width=1000, height=800)

default_font = tkFont.nametofont("TkDefaultFont")
default_font.configure(size=12)
self.root.option_add("*Font", default_font)
... 
self.root.mainloop()
...

tells me that 'tkFont' is not defined. What am I missing?

As always, thanks for any pointers!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The computer that mastered Go

2016-01-29 Thread Paul Rubin
mm0fmf  writes:
> Is it written in Python?

One would expect it to be written in Go, but it turns out to be C++ and
Lua :(.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Gregory Ewing

[email protected] wrote:

On Thursday, January 28, 2016 at 6:34:34 PM UTC-8, Chris Angelico wrote:


https://xkcd.com/353/


I have this comic pinned to the outside wall of my cubicle at work, where I
use Python for 98% of my work.


Another good thing to pin to your wall:

http://www.gentoogeek.org/files/choose_python.pdf

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


Re: The computer that mastered Go

2016-01-29 Thread mm0fmf via Python-list

On 29/01/2016 22:13, Paul Rubin wrote:

mm0fmf  writes:

Is it written in Python?


One would expect it to be written in Go, but it turns out to be C++ and
Lua :(.



Why did he post it in comp.lang.python then?
--
https://mail.python.org/mailman/listinfo/python-list


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Rick Johnson
On Friday, January 29, 2016 at 2:49:24 PM UTC-6, [email protected] wrote:

> I'm convinced that anyone who actually prefers Perl's
> syntax over Python is suffering from Stockholm Syndrome.
>
> [...]
>
> Readability counts.  I'd say readability is one of the
> most important features of a language, as you will read
> your code far more than you write it.  Perl is not
> readable.  I don't care how powerful your language is if
> you can't read it.

EXACTLY!

Which is the same reason why natural language is bound by
many structural rules. For instance: we utilize "syntactical
structures" like sentences and paragraphs to create
"comprehensible groupings", and we *NEVER* want to
arbitrarily, or randomly, use more than one space between
words, or more than one line between paragraphs.

STRUCTURE IS IMPORTANT!

And the only thing more important than a "self-imposed
structure" is a steadfast adherence to the "collective style
guides" of written communication. When we *ALL* utilize a
familiar structure, we will *ALL* spend less time
*CONSCIOUSLY INTERPRETING* superficial structural details,
and more time *ABSORBING* the actual meaning of the content.

ABSORPTION IS THE GOAL, NOT ABERRATION!

The goal of written communication is no different than any
other technology. We should strive to abstract away as much
as possible to the sub-conscience processes of our mind as
we can, so that we can target our mental focus purely on the
comprehension of content, *NOT* comprehension of structure!
When faced with an unfamiliar "syntactical structure", our
high level focus becomes "mired in the minutiae of the
superficial".

EVEN WHEN NECESSARY, THE SUPERFICIAL IS NOT IMPORTANT!

The goal of communication should never be (either
intentional or not) to distract or impress our readers with
our capacity to create "self-aggrandizing ornateness of
structure", which will undoubtedly obfuscate the intended
message, no, but to *STRICTLY* follow the collective
standards and practices of "acceptable syntactical
structuring" that will *facilitate* a smooth transition
between: ideas that are codified into symbolic languages,
and the translation of those linguistic symbols into concepts
in the mind of the reader.

ABSTRACTIONS ARE VITAL TO OUR COMPREHENSION OF COMPLEX
COMMUNICATION MEDIUMS!

For communication to function (at it's most basic level)
these abstractions must exist simultaneously in our codified
symbolic languages *AND* in our mental processes that
interpret them. But whilst our mental abstractions are
mostly unconscious, they can become disturbed when
dissonance is injected into symbolic languages in the form
of "poor syntactical structure". Break either link in the
chain, and a "smooth transition of ideas" becomes untenable.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Ben Finney
Steven D'Aprano  writes:

> You should have started with the official tutorial:
>
> https://docs.python.org/2/tutorial/

And these days the default recommendation should be to start with the
official tutorial for the current stable version of the Python language,
Python 3 https://docs.python.org/3/tutorial/>.

-- 
 \   “We jealously reserve the right to be mistaken in our view of |
  `\  what exists, given that theories often change under pressure |
_o__)  from further investigation.” —Thomas W. Clark, 2009 |
Ben Finney

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


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Fillmore

On 1/29/2016 4:30 PM, Rick Johnson wrote:

 People who are unwilling to "expanding their
intellectual horizons" make me sick!!!


did I miss something or is this aggressiveness unjustified?


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


Re: The computer that mastered Go

2016-01-29 Thread Bernardo Sulzbach
On Fri, Jan 29, 2016 at 8:13 PM, Paul Rubin  wrote:
> One would expect it to be written in Go, but it turns out to be C++ and
> Lua :(.

I can only contribute with my sadness and disappointment. =(

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


Re: The computer that mastered Go

2016-01-29 Thread Bernardo Sulzbach
On Fri, Jan 29, 2016 at 8:25 PM, mm0fmf via Python-list
 wrote:
>
> Why did he post it in comp.lang.python then?
>

I don't know. I must say that it is a pretty good video, though. Much
more interesting than the average "How to install Python? What have
you tried? Asking here." that goes on every now and then.

Ultimately, I do agree with you that this is OT, even if I don't mind it.

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


Re: Font issues Tkinter/Python 3.5

2016-01-29 Thread MRAB



On 2016-01-29 22:04:57, "KP"  wrote:


import tkinter as tk
from tkinter import ttk
from tkinter import font
...
def __init__(self):
self.root = tk.Tk()
self.root.title('Main Window')
self.root.geometry('1000x800+200+200')
self.root.minsize(width=1000, height=800)

default_font = tkFont.nametofont("TkDefaultFont")
default_font.configure(size=12)
self.root.option_add("*Font", default_font)
...
self.root.mainloop()
...

tells me that 'tkFont' is not defined. What am I missing?

As always, thanks for any pointers!

 'nametofont' is in tkinter.font, which you have imported as 'font', so 
'tkFont.nametofont' should be 'font.nametofont'.


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


Re: psss...I want to move from Perl to Python

2016-01-29 Thread MRAB

On 2016-01-30 00:57:10, "Fillmore"  wrote:


On 1/29/2016 4:30 PM, Rick Johnson wrote:

 People who are unwilling to "expanding their
intellectual horizons" make me sick!!!


did I miss something or is this aggressiveness unjustified?

In the past, he has posted under the name "Ranting Rick", which is apt, 
because he has a tendency to rant, like you have just witnessed...


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


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Cameron Simpson

On 29Jan2016 18:12, Steven D'Aprano  wrote:

On Fri, 29 Jan 2016 11:25 am, Chris Angelico wrote:


Probably the biggest thing to take note of is the Python object model
- how names and objects and assignment work. It's pretty
straight-forward, but if it's not what you're used to, you'll need to
get your head around it. Here's a good talk on the subject:

http://nedbatchelder.com/text/names1.html


Every time I make a half-hearted attempt to learn enough Perl syntax to get
started, I keep running into the differences between $foo, %foo and @foo
and dire warnings about what happens if you use the wrong sigil, and then I
get confused. Is there a good discussion of how names and references work
in Perl, equivalent to Ned's discussion?


The prefices:

$ = scalar (numbers and strings)
@ = array (lists)
% = hashes (dicts/mappings)

They are distinct namespaces, so you can use $foo and %foo in the same code for 
different variables. No, I don't think that is a good idea.


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


How to resize an animated gif to fit the window

2016-01-29 Thread kwekey
Hi, I am able to display animated gif using pyglet using below code, but I 
would like the image to stretch and fit the window as i resize the window.
Any one can help me?

import pyglet
# pick an animated gif file you have in the working directory

CODE: SELECT ALL
def animate(str):
ag_file = str
animation = pyglet.resource.animation(ag_file)
sprite = pyglet.sprite.Sprite(animation)
# create a window and set it to the image size
win = pyglet.window.Window(width=sprite.width, height=sprite.height)
  
@win.event
def on_draw():
win.clear()
sprite.draw()

pyglet.app.run()

animate("***.gif")


CODE: SELECT ALL
win = pyglet.window.Window(width=sprite.width, height=sprite.height)

Above line will resize the window to fit the animated gif but i want it the 
other way, that is the gif to fit the windows size..
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Josef Pktd
On Friday, January 29, 2016 at 4:50:25 PM UTC-5, Cody Piersall wrote:
> On Fri, Jan 29, 2016 at 2:42 PM, Fillmore 
> wrote:
> > I actually have a few followup question.
> 
> > - will iNotebook also work in Python 3?
> Yes!  And just FYI, it's called they Jupyter Notebook now, but pretty much
> everyone still (colloquially) calls it the IPython Notebook so you're in
> good company.  When you're searching online, you should search for Jupyter
> though, or you might get obsolete docs.
> 
> > - What version of Python 3 do you recommend I install on Windows?
> Might as well go for Python 3.5.
> 
> > [snip questions I don't know the answer to]
> > - Is there a good IDE that can be used for debugging? all free IDEs for
> Perl suck and it would be awesome if Python was better than that.
> PyCharm is a really good IDE.  You can use the community edition for free
> as long as it's for open source projects or your company makes less than $1
> million a year.  For bigger projects I use PyCharm, but it's not bad to use
> just a plain text editor either.  If your company is making $1 million a
> year, presumably they can afford the license fees.  Download link:
> https://www.jetbrains.com/pycharm/download/

spyder is great for developing scripts (especially data analysis and scientific)
pydev/eclipse is very good for larger packages or projects.

Great features: automatic, immediate code checking for finding those typos, 
undefined names and unused names, and similar  (look out for red)
(and of course code completion, nicer than in IDLE)

Another very useful tool for me during bug hunting sessions is to drop into the 
debugger when running nosetests.

In my experience notebooks are for when I know what I'm doing and want a nice 
summary or presentation, but not when I need to figure out what I'm supposed to 
be doing.

Josef

> 
> Cody

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


Re: Pyhon Icon

2016-01-29 Thread Terry Reedy

On 1/29/2016 6:00 AM, Walter Nakatana wrote:


Every time I install python , I don't see the icon on my desktop


Correct.  The Windows installer puts 5 icons-entries under a Python x.y 
entry in the Start Menu (or All apps in Win 10).  It does not put any on 
the desktop.  You can easily copy from Start Menu to Desktop if you 
want.  Win 10 makes this much harder (I forget how I did it).



neither in my C: drive


I do not understand 'icon in C: drive'.  If you use Windows Explorer, 
you will find a Pythonxy either in the default location or wherever you 
said to put it.



--
Terry Jan Reedy

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


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Ben Finney
Fillmore  writes:

> On 1/29/2016 4:30 PM, Rick Johnson wrote:
> >  People who are unwilling to "expanding their
> > intellectual horizons" make me sick!!!
>
> did I miss something or is this aggressiveness unjustified?

Indeed it is unjustified. The person to whom you respond is best ignored
(automatically, via a kill-file in your program). No matter how amusing
some trainwreck-chasers may find his outbursts, his unreasoning
hostility is disruptive.

-- 
 \ “What is it that makes a complete stranger dive into an icy |
  `\   river to save a solid gold baby? Maybe we'll never know.” —Jack |
_o__)   Handey |
Ben Finney

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


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Rustom Mody
On Saturday, January 30, 2016 at 3:01:09 AM UTC+5:30, Rick Johnson wrote:
> On Friday, January 29, 2016 at 6:21:21 AM UTC-6, Ulli Horlacher wrote:
> > I nearly gave up with Python at the very beginning before
> > I realised that OO-programming is optional in Python! :-)
> > Most tutorials I found so far makes OO mandatory.
> 
> Just more evidence that old dogs are incapable of learning
> new tricks. Either learn how to wield Neuroplasticity to
> your advantage, or go curl up into a ball and wait for death
> to come. People who are unwilling to "expanding their
> intellectual horizons" make me sick!!!

JFTR:
[Ranting] Rick is someone who I sometimes agree with were it not for the 
ranting style.

In this case I think its more important to rebut the contents of the rant than
the emotion-BS, especially given that one of the questions of the OP was re 
're'.

Somebody said above that the re in python needs to be 'compiled' unlike perl.
Also if you see the docs they are mostly match/search orientated.

Both these are unnecessary OO-gook

1. One can use string-re's instead of compiled re's
2. One can use findall instead of search/match
3. One can do 
from re import findall
findall(...)

rather than

import re
re.findall(...)


1. By using string-res one need not create opaque re OBJECTS
2. By using findall one need not fish around in opaque match objects
3. By using from ... import one can reduce OO dotodotodotomania

In short python can be much less OO than is typically presented
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: show instant data on webpage

2016-01-29 Thread Grobu

On 26/01/16 17:10, mustang wrote:

I've built a sensor to measure some values.
I would like to show it on a web page with python.


This is an extract of the code:

file  = open("myData.dat", "w")

while True:
 temp = sensor.readTempC()
 riga = "%f\n" % temp
 file.write(riga)
 time.sleep(1.0)

file.close()

Until this all ok.
Then in PHP I read the file and show it on internet. It works ok but...
First problem. I've to stop the streaming with CTRl-C to load the PHP
file because if I try to read during measurement I cannot show anything
(I think because the file is in using).
How can I show time by time in a webpage the output?



Perhaps you could use a Javascript plotting library (like the one at 
flotcharts.org), and use Python only as a CGI agent to serve plotting 
data when requested by Javascript, at regular intervals?


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


Re: Mimick tac with python.

2016-01-29 Thread Chris Angelico
On Sat, Jan 30, 2016 at 3:46 PM, Hongyi Zhao  wrote:
> I can use the following methods for mimicking tac command bellow:
>
> awk '{a[NR]=$0} END {while (NR) print a[NR--]}' input_file
> perl -e 'print reverse<>' input_file
>
> Is it possible to do the same thing with python?

python -c 'import sys; print("".join(list(open(sys.argv[1]))[::-1]))' input_file

Python doesn't have a short-hand for grabbing the file named as an
argument, but it's easy enough to reverse stuff.

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


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Terry Reedy

On 1/29/2016 3:51 PM, Chris Angelico wrote:

On Sat, Jan 30, 2016 at 7:42 AM, Fillmore  wrote:



- Is there a good IDE that can be used for debugging? all free IDEs for Perl
suck and it would be awesome if Python was better than that.



Debugging Python code is generally easy enough without an IDE; any
time something goes wrong, you get an exception with a very pretty
traceback. That's usually enough on its own. A little bit of editor
integration can help you jump to the lines mentioned, in the same way
that you might get that with C compiler errors; that's all I've ever
needed.


When one runs code from an IDLE editor, output and exceptions go to the 
IDLE Shell.  Right click on a traceback line and select 'Go to 
file/line' and IDLE will display the file in an IDLE editor (opening it 
if necessary) and put the cursor on the proper line.  (It does the same 
with grep output.)


--
Terry Jan Reedy


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


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Chris Angelico
On Sat, Jan 30, 2016 at 2:08 PM, Terry Reedy  wrote:
> On 1/29/2016 3:51 PM, Chris Angelico wrote:
>>
>> On Sat, Jan 30, 2016 at 7:42 AM, Fillmore 
>> wrote:
>
>
>>> - Is there a good IDE that can be used for debugging? all free IDEs for
>>> Perl
>>> suck and it would be awesome if Python was better than that.
>>>
>>
>> Debugging Python code is generally easy enough without an IDE; any
>> time something goes wrong, you get an exception with a very pretty
>> traceback. That's usually enough on its own. A little bit of editor
>> integration can help you jump to the lines mentioned, in the same way
>> that you might get that with C compiler errors; that's all I've ever
>> needed.
>
>
> When one runs code from an IDLE editor, output and exceptions go to the IDLE
> Shell.  Right click on a traceback line and select 'Go to file/line' and
> IDLE will display the file in an IDLE editor (opening it if necessary) and
> put the cursor on the proper line.  (It does the same with grep output.)

Yep. Same happens if you run the file from SciTE, and probably a lot
of other editors too. I don't call them "IDEs" because of that one
feature, but honestly, I don't need anything more of an IDE.

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


Re: Mimick tac with python.

2016-01-29 Thread Christian Gollwitzer

Am 30.01.16 um 05:58 schrieb Random832:

On Fri, Jan 29, 2016, at 23:46, Hongyi Zhao wrote:

awk '{a[NR]=$0} END {while (NR) print a[NR--]}' input_file
perl -e 'print reverse<>' input_file


Well, both of those read the whole file into memory - tac is sometimes
smarter than that, but that makes for a more complex program.


Now I'm curious. How is it possible to output the first line as last 
again if not by remembering it from the every beginning? How could tac 
be implemented other than sucking up everything into memory?


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


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Rustom Mody
On Saturday, January 30, 2016 at 3:01:09 AM UTC+5:30, Rick Johnson wrote:
> On Friday, January 29, 2016 at 6:21:21 AM UTC-6, Ulli Horlacher wrote:
> > I nearly gave up with Python at the very beginning before
> > I realised that OO-programming is optional in Python! :-)
> > Most tutorials I found so far makes OO mandatory.
> 
> Just more evidence that old dogs are incapable of learning
> new tricks. Either learn how to wield Neuroplasticity to
> your advantage, or go curl up into a ball and wait for death
> to come. 

Regarding neuroplasticity especially in programming you may find this useful:

http://blog.languager.org/2016/01/primacy.html

> People who are unwilling to "expanding their intellectual horizons" make me 
> sick!!!

Yes!

And as functional programming becomes more mainstream, OO-fanboys
may need some urgent graft of plastic, see:

http://blog.languager.org/2015/06/functional-programming-moving-target.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Mimick tac with python.

2016-01-29 Thread Hongyi Zhao
On Fri, 29 Jan 2016 23:58:38 -0500, Random832 wrote:

> python <(echo 'import sys;print("".join(reversed(list(sys.stdin')

Why do you write it as follows:

cat input_file | python -c 'import sys;print("".join(reversed(list
(sys.stdin'

Regards
-- 
.: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
-- 
https://mail.python.org/mailman/listinfo/python-list


Mimick tac with python.

2016-01-29 Thread Hongyi Zhao
Hi all,

I can use the following methods for mimicking tac command bellow:

awk '{a[NR]=$0} END {while (NR) print a[NR--]}' input_file
perl -e 'print reverse<>' input_file

Is it possible to do the same thing with python?

Regards
-- 
.: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Mimick tac with python.

2016-01-29 Thread Random832
On Fri, Jan 29, 2016, at 23:46, Hongyi Zhao wrote:
> Hi all,
> 
> I can use the following methods for mimicking tac command bellow:
> 
> awk '{a[NR]=$0} END {while (NR) print a[NR--]}' input_file
> perl -e 'print reverse<>' input_file

Well, both of those read the whole file into memory - tac is sometimes
smarter than that, but that makes for a more complex program. And python
doesn't really do "one-liners" like that, so it doesn't look quite as
nice. But combined with some shell constructs you can do:

python <(echo 'import sys;print("".join(reversed(list(sys.stdin')
-- 
https://mail.python.org/mailman/listinfo/python-list