socket: Did I find a bug?

2018-03-08 Thread Antoon Pardon
This is on a debian 9 box python 2.7.13

My interpretation is that a timeout exception is thrown and that the
args attribute of such an exception is an empty tuple which then causes
an IndexError in line 482 of module /usr/lib/python2.7/socket.py. Does
that soundplausible?

Here is the traceback:

Traceback (most recent call last):
  File "/usr/local/lib/python-apps/rmtdump/pymain.py", line 101, in main
Exit_Nr = process(sys.argv)
  File "/usr/local/lib/python-apps/rmtdump/rmtdump.py", line 249, in program
process(path)
  File "/usr/local/lib/python-apps/rmtdump/rmtdump.py", line 184, in process
of = rmt.open(rpj(rmt5lcl(rt), archive), "wb")
  File "/usr/local/lib/python-apps/rmtdump/ftputil.py", line 211, in open
return ftpfile(ftp, fn, mode, True)
  File "/usr/local/lib/python-apps/rmtdump/ftputil.py", line 70, in __init__
self.cnct =  self.ftp.transfercmd("%s %s" % (cmd, rfn))
  File "/usr/lib/python2.7/ftplib.py", line 376, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
  File "/usr/lib/python2.7/ftplib.py", line 710, in ntransfercmd
conn, size = FTP.ntransfercmd(self, cmd, rest)
  File "/usr/lib/python2.7/ftplib.py", line 339, in ntransfercmd
resp = self.sendcmd(cmd)
  File "/usr/lib/python2.7/ftplib.py", line 249, in sendcmd
return self.getresp()
  File "/usr/lib/python2.7/ftplib.py", line 215, in getresp
resp = self.getmultiline()
  File "/usr/lib/python2.7/ftplib.py", line 201, in getmultiline
line = self.getline()
  File "/usr/lib/python2.7/ftplib.py", line 186, in getline
line = self.file.readline(self.maxline + 1)
  File "/usr/lib/python2.7/socket.py", line 482, in readline
if e.args[0] == EINTR:
IndexError: tuple index out of range
Locals by frame, innermost last

Frame main in /usr/local/lib/python-apps/rmtdump/pymain.py at line 119
   backtrace = 
 fun = 
  pn = 'rmtdump'
 process = 

Frame program in /usr/local/lib/python-apps/rmtdump/rmtdump.py at line 281
 ErrInfo = IndexError('tuple index out of range',)
 aborted = True
argv = ['/usr/local/sbin/rmtdump']
path = '/home/antoon'

Frame process in /usr/local/lib/python-apps/rmtdump/rmtdump.py at line 208
 ErrInfo = IndexError('tuple index out of range',)
b_rt = 
'/home/antoon/.icedove/clam9zaw.default/ImapMail/mail.priorweb.be'
  backupflag = 'rwx'
 backupstamp = 1520450190
  checkstamp = 1519846075
  cleanstamp = 1
dirs = ['Archives-1.sbd', 'INBOX.sbd']
 entries = ['@TODO.msf', 'Archives-1.msf', 'Archives-1.sbd', 
'Archives.msf', 'Drafts-1.msf', 'Drafts.msf', 'INBOX', ...
   entry = 'msgFilterRules.dat'
   file_info = posix.stat_result(st_mode=33188, st_ino=10365097, 
st_dev=2058, st_nlink=1, st_uid=1000, st_gid=1000, st_ ...
fileinfo = posix.stat_result(st_mode=33152, st_ino=10621705, 
st_dev=2058, st_nlink=1, st_uid=1000, st_gid=1000, st_ ...
   files = ['Junk.msf', 'Drafts.msf', 'filterlog.html', 
'Drafts-1.msf', 'Archives.msf', 'junklog.html', 'msgFilterR ...
   filestamp = 1463826952.531162
fqpn = 
'/home/antoon/.icedove/clam9zaw.default/ImapMail/mail.priorweb.be/msgFilterRules.dat'
  islink = 
 ismount = 
last = 1520450604.318512
ls_stamp = ['+1520450190', '1519846075', '1', '0', '0']
   newfn = 
'home/antoon/.icedove/clam9zaw.default/ImapMail/mail.priorweb.be/!2018-03-07@20_16_30-tbz'
 now = 1520450549
 nr_of_tries = 0
  of = None
   oldfn = 
'home/antoon/.icedove/clam9zaw.default/ImapMail/mail.priorweb.be/!ENTRY-tbz'
path = '/home/antoon'
  rt = 
'/home/antoon/.icedove/clam9zaw.default/ImapMail/mail.priorweb.be'
st_stamp = '+1520450190:1519846075:1'
   stamp = '1'
   start = 1520450604
  tf = 
  timefn = '!2018-03-07@20_16_30-tbz'
   tryal = 0
  update = True

Frame open in /usr/local/lib/python-apps/rmtdump/ftputil.py at line 211
  fn = 
'home/antoon/.icedove/clam9zaw.default/ImapMail/mail.priorweb.be/!ENTRY-tbz'
 ftp = FTPS(ant...@pardon-sleeuwaegen.be@ftp.adrive.com)
mode = 'wb'
self = FTPS(ant...@pardon-sleeuwaegen.be@ftp.adrive.com)

Frame __init__ in /usr/local/lib/python-apps/rmtdump/ftputil.py at line 70
   bound = True
  ch = 'b'
 cmd = 'STOR'
  cn = FTPS(ant...@pardon-sleeuwaegen.be@ftp.adrive.com)
   count = 1
mode = 'wb'
 rfn = 
'home/antoon/.icedove/clam9zaw.default/ImapMail/mail.priorweb.be/!ENTRY-tbz'
self = None

Frame transfercmd in /usr/lib/python2.7/ftplib.py at line 376
   

Re: Which part of the loop is it going through in this class frame?

2018-03-08 Thread Steven D'Aprano
On Wed, 07 Mar 2018 16:57:51 -0500, C W wrote:

> Hello,
> 
> I am new to OOP. I'm a bit confused about the following code.
> 
> class Clock(object):
> def __init__(self, time):
> self.time = time

Here you set the instance attribute "self.time".

> def print_time(self):
> time = '6:30'
> print(self.time)

Here you set the local variable "time", which is completely unrelated to 
the attribute "self.time".

If you are used to languages where "foo" inside a method is a short-cut 
for "self.foo" or "this.foo", Python does not do that. Local variables 
and instance attributes are distinct concepts, and Python keeps them 
distinct.


> How does line-by-line execution run inside a frame? 

There isn't actually line-by-line execution as such, although it can be 
very similar. Before the interpreter runs Python code, it compiles it to 
byte-code, and then runs the byte-code. A single line of source code 
could result in any number of lines of byte code, from zero to an 
unlimited number. 

> How does __init__
> work? I understand you must have __init__. 

You understand wrongly then :-)

It is normal and common to have an __init__ method, but it is not 
compulsory. If your class doesn't need one, you don't need to write it.

The __init__ method is the initialiser. Think of it as very similar to 
the constructor in some other languages, and for now the differences 
aren't important. The usual purpose of the __init__ method is to 
initialise the instance and set any attributes needed.

> Is it run before print_time(),

The __init__ method is called once, when the instance is first created. 
So the short answer is, yes, it will run before print_time(). But only 
once.

> if so, why don't I just set self.time = '6:30' instead of
> self.time = time?

Because then every instance will be set to 6:30, instead of letting you 
set each instance to a different time.



-- 
Steve

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


Re: socket: Did I find a bug?

2018-03-08 Thread INADA Naoki
https://mail.python.org/pipermail/python-list/2016-February/703154.html

On Thu, Mar 8, 2018 at 8:09 PM, Antoon Pardon  wrote:
> This is on a debian 9 box python 2.7.13
>
> My interpretation is that a timeout exception is thrown and that the
> args attribute of such an exception is an empty tuple which then causes
> an IndexError in line 482 of module /usr/lib/python2.7/socket.py. Does
> that soundplausible?
>
> Here is the traceback:
>
> Traceback (most recent call last):
>   File "/usr/local/lib/python-apps/rmtdump/pymain.py", line 101, in main
> Exit_Nr = process(sys.argv)
>   File "/usr/local/lib/python-apps/rmtdump/rmtdump.py", line 249, in program
> process(path)
>   File "/usr/local/lib/python-apps/rmtdump/rmtdump.py", line 184, in process
> of = rmt.open(rpj(rmt5lcl(rt), archive), "wb")
>   File "/usr/local/lib/python-apps/rmtdump/ftputil.py", line 211, in open
> return ftpfile(ftp, fn, mode, True)
>   File "/usr/local/lib/python-apps/rmtdump/ftputil.py", line 70, in __init__
> self.cnct =  self.ftp.transfercmd("%s %s" % (cmd, rfn))
>   File "/usr/lib/python2.7/ftplib.py", line 376, in transfercmd
> return self.ntransfercmd(cmd, rest)[0]
>   File "/usr/lib/python2.7/ftplib.py", line 710, in ntransfercmd
> conn, size = FTP.ntransfercmd(self, cmd, rest)
>   File "/usr/lib/python2.7/ftplib.py", line 339, in ntransfercmd
> resp = self.sendcmd(cmd)
>   File "/usr/lib/python2.7/ftplib.py", line 249, in sendcmd
> return self.getresp()
>   File "/usr/lib/python2.7/ftplib.py", line 215, in getresp
> resp = self.getmultiline()
>   File "/usr/lib/python2.7/ftplib.py", line 201, in getmultiline
> line = self.getline()
>   File "/usr/lib/python2.7/ftplib.py", line 186, in getline
> line = self.file.readline(self.maxline + 1)
>   File "/usr/lib/python2.7/socket.py", line 482, in readline
> if e.args[0] == EINTR:
> IndexError: tuple index out of range
> Locals by frame, innermost last
>
> Frame main in /usr/local/lib/python-apps/rmtdump/pymain.py at line 119
>backtrace = 
>  fun = 
>   pn = 'rmtdump'
>  process = 
>
> Frame program in /usr/local/lib/python-apps/rmtdump/rmtdump.py at line 281
>  ErrInfo = IndexError('tuple index out of range',)
>  aborted = True
> argv = ['/usr/local/sbin/rmtdump']
> path = '/home/antoon'
>
> Frame process in /usr/local/lib/python-apps/rmtdump/rmtdump.py at line 208
>  ErrInfo = IndexError('tuple index out of range',)
> b_rt = 
> '/home/antoon/.icedove/clam9zaw.default/ImapMail/mail.priorweb.be'
>   backupflag = 'rwx'
>  backupstamp = 1520450190
>   checkstamp = 1519846075
>   cleanstamp = 1
> dirs = ['Archives-1.sbd', 'INBOX.sbd']
>  entries = ['@TODO.msf', 'Archives-1.msf', 'Archives-1.sbd', 
> 'Archives.msf', 'Drafts-1.msf', 'Drafts.msf', 'INBOX', ...
>entry = 'msgFilterRules.dat'
>file_info = posix.stat_result(st_mode=33188, st_ino=10365097, 
> st_dev=2058, st_nlink=1, st_uid=1000, st_gid=1000, st_ ...
> fileinfo = posix.stat_result(st_mode=33152, st_ino=10621705, 
> st_dev=2058, st_nlink=1, st_uid=1000, st_gid=1000, st_ ...
>files = ['Junk.msf', 'Drafts.msf', 'filterlog.html', 
> 'Drafts-1.msf', 'Archives.msf', 'junklog.html', 'msgFilterR ...
>filestamp = 1463826952.531162
> fqpn = 
> '/home/antoon/.icedove/clam9zaw.default/ImapMail/mail.priorweb.be/msgFilterRules.dat'
>   islink = 
>  ismount = 
> last = 1520450604.318512
> ls_stamp = ['+1520450190', '1519846075', '1', '0', '0']
>newfn = 
> 'home/antoon/.icedove/clam9zaw.default/ImapMail/mail.priorweb.be/!2018-03-07@20_16_30-tbz'
>  now = 1520450549
>  nr_of_tries = 0
>   of = None
>oldfn = 
> 'home/antoon/.icedove/clam9zaw.default/ImapMail/mail.priorweb.be/!ENTRY-tbz'
> path = '/home/antoon'
>   rt = 
> '/home/antoon/.icedove/clam9zaw.default/ImapMail/mail.priorweb.be'
> st_stamp = '+1520450190:1519846075:1'
>stamp = '1'
>start = 1520450604
>   tf = 
>   timefn = '!2018-03-07@20_16_30-tbz'
>tryal = 0
>   update = True
>
> Frame open in /usr/local/lib/python-apps/rmtdump/ftputil.py at line 211
>   fn = 
> 'home/antoon/.icedove/clam9zaw.default/ImapMail/mail.priorweb.be/!ENTRY-tbz'
>  ftp = FTPS(ant...@pardon-sleeuwaegen.be@ftp.adrive.com)
> mode = 'wb'
> self = FTPS(ant...@pardon-sleeuwaegen.be@ftp.adrive.com)
>
> Frame __init__ in /usr/local/lib/python-apps/rmtdump/ftputil.py at line 70
>bound = True
>   ch = 'b'
>  cmd = 'STOR'
>   

EuroPython 2018: Our conference logo

2018-03-08 Thread M.-A. Lemburg
After intense work with our designer, we are happy to present the logo
for the EuroPython 2018 conference:

https://blog.europython.eu/post/171656128512/europython-2018-our-conference-logo

The colors and patterns are a play on Scottish kilts, referring to the
location, and a theatre curtain, representing the many presentations
we’ll have at the conference.

We hope you like it as much as we do.


Enjoy,
--
EuroPython 2018 Team
https://ep2018.europython.eu/
https://www.europython-society.org/


PS: Please forward or retweet to help us reach all interested parties:
https://twitter.com/europython/status/971716219232575488
Thanks.

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


EuroPython 2018: Hotel tips and general update

2018-03-08 Thread M.-A. Lemburg
As you may know, the Edinburgh Fringe Festival is starting one week
after EuroPython 2018 in Edinburgh. Since this typically attracts many
thousands of people and artists, the hotels are filling up quickly in
Edinburgh.

If you’re planning to attend EuroPython, please book your hotel
early. Many booking sites offer free cancellations, so there’s no risk
in making reservations now, even if you decide not to come in the end.

Room allocation for EuroPython 2018
---

To help with this, we have partnered with the Edinburgh Convention
Bureau to set aside a number of hotel rooms which are reserved for
EuroPython attendees. These rooms will be held reserved until a few
weeks before the conference and are also available with a free
cancellation option.

The Edinburgh Convention Bureau has setup the following website for
booking rooms from this allocation:

* EuroPython 2018 Hotel Booking Website *
https://cabsedinburgh.eventsair.com/QuickEventWebsitePortal/europython-2018/home-page
(run by the Edinburgh Convention Bureau)


Update on EuroPython 2018
-

Meanwhile, we wanted to give you an update of where we are with the
conference organization:

We are still working on getting everything setup for launching the
website, opening ticket sales and the Call for Proposals (CFP).

This year the EuroPython Society (EPS) will be running the ticket
sales, rather than a local organization and we are facing some
challenges related to VAT taxes, which are taking longer to sort out
than expected.

This is the main reason for the delay you are seeing, but we’re
getting there.


Enjoy,
--
EuroPython 2018 Team
https://ep2018.europython.eu/
https://www.europython-society.org/


PS: Please forward or retweet to help us reach all interested parties:
https://twitter.com/europython/status/971716086445027328
Thanks.

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


ANN: pygameweb 0.0.4 - Northern Rockhopper Penguin

2018-03-08 Thread René Dudfield
G'day.




pygameweb  is the source code for
the pygame
website  at https://www.pygame.org/

[image: 6954251406_95ebe75f55_m]


   - #52  Adding ability to
   deploy through travisci. And docs.
   - #46  Wiki readability.
   Wiki tools on left out of reading line.
   - Twitter card for releases. For nicer view when posting to twitter.
   - Wiki table of contents improvements.
   - builds docs for pygame, when something lands on pygame github master
   branch.
   - project release feeds bugfix.
   - Only show one recent release for each project. Some projects release a
   few times in a row.
   - Wiki, nicer pre code handling.
   - Wiki code uses inline colors, so copy/paste works with colors too.
   - use https for login and register buttons, even when on http (see Why
   can't we turn off HTTPS?
   ).
   - Ask more bad robot web crawlers not to be bad.

See a full diff of changes since last release
.

Majestic photo of a Northern Rockhopper Penguin by Brian Gratwicke

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


psychocomputational analysis toolkit in Python?

2018-03-08 Thread Etienne Robillard

Hi

i want to develop a psychocomputational analysis toolkit in python for 
studying real-time neuroimaging data from focused 
ultrasound/brain-to-brain interfaces.


Any suggestions where to look for cool projects in github? :)

Best regards,

Etienne


--
Etienne Robillard
tkad...@yandex.com
https://www.isotopesoftware.ca/
https://www.isotoperesearch.ca/

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


Re: psychocomputational analysis toolkit in Python?

2018-03-08 Thread Christopher Mullins
You might find MNE useful, and if what you're doing happens to fit
somewhere in their package you could contribute to it -- they're a good
group to work with.

https://www.martinos.org/mne/stable/index.html
https://github.com/mne-tools/mne-python
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: psychocomputational analysis toolkit in Python?

2018-03-08 Thread Etienne Robillard

Thanks for sharing this link. MNE looks pretty cool. :-)

I'm mostly interested in mapping specific cortical pathways to 
brain-to-brain interfaces implicated in the ultrasonic neuromodulation 
of behavior.


Would it be possible to emulate a minimally functional brain-to-brain 
coupling system entirely in Python?


Best regards,

Etienne


Le 2018-03-08 à 09:44, Christopher Mullins a écrit :
You might find MNE useful, and if what you're doing happens to fit 
somewhere in their package you could contribute to it -- they're a 
good group to work with.


https://www.martinos.org/mne/stable/index.html
https://github.com/mne-tools/mne-python


--
Etienne Robillard
tkad...@yandex.com
https://www.isotoperesearch.ca/

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


Re: psychocomputational analysis toolkit in Python?

2018-03-08 Thread Christopher Mullins
> Would it be possible to emulate a minimally functional brain-to-brain
coupling system entirely in Python?

I don't know what that would entail, but the links I shared have a mailing
list and a very responsive gitter, both of which would be great places to
ask about that!  (You're welcome to ask here of course, but this being the
general python mailing list, it's a shot in the dark.)  Good luck!

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


Re: psychocomputational analysis toolkit in Python?

2018-03-08 Thread Bob Gailer
On Mar 8, 2018 10:08 AM, "Etienne Robillard"  wrote:
>
> Thanks for sharing this link. MNE looks pretty cool. :-)
>
> I'm mostly interested in mapping specific cortical pathways to
brain-to-brain interfaces implicated in the ultrasonic neuromodulation of
behavior.
>
> Would it be possible to emulate a minimally functional brain-to-brain
coupling system entirely in Python?

Since python is a general purpose programming language, I'd say yes. I
would add the use of a database management system, since you need some way
of storing the data. sqlite is an excellent database management system with
an excellent python interface. Unlike other database systems, sqlite is
single-user system. You can always migrate later to a multi-user system.

The sqlite3 module is included in the python distribution.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: psychocomputational analysis toolkit in Python?

2018-03-08 Thread Etienne Robillard

OK I got it, thank you! :)

Essentially, I want to develop a psychocomputational analysis toolkit in 
Python for studying real-time neuroimaging data (of cortical activity) 
from low-intensity, focused ultrasounds (LIFU) and possibly emulate a 
functional brain-to-brain coupling system on my 32-bit computer as a 
proof-of-concept to demonstrate the vulnerability of the human cochlear 
pathway to become a target of sophisticated ultrasonic side-channel 
attacks from mobile devices.


Etienne


Le 2018-03-08 à 10:31, Christopher Mullins a écrit :
> Would it be possible to emulate a minimally functional 
brain-to-brain coupling system entirely in Python?


I don't know what that would entail, but the links I shared have a 
mailing list and a very responsive gitter, both of which would be 
great places to ask about that!  (You're welcome to ask here of 
course, but this being the general python mailing list, it's a shot in 
the dark.)  Good luck!


Chris


--
Etienne Robillard
tkad...@yandex.com
https://www.isotoperesearch.ca/

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


Unnoticed traceback in a thread

2018-03-08 Thread Skip Montanaro
I have a program which is almost always running in a single thread. It
uses a daemon thread (via threading.Timer) to periodically checkpoint
some state. The program runs for days at a time.

Over the past couple days, two instances of the subthread croaked with
tracebacks because while they were iterating over the checkpointable
data, the main thread modified the data. Blammo! It was an easy fix
(threading.Lock) and everything is back on an even keel.

After the bug was tickled, the program continued to do its thing. It
just stopped checkpointing. Given the way the program is managed, the
traceback wound up in an obscure log file, and it was a couple days
before I noticed it. I've seen this sort of
thread-dies-but-program-doesn't-crash situation before. I can look at
ways to more actively monitor the contents of the obscure log file,
but is there some non-hackish way that the demise of the daemon thread
can take down the entire program? (Sometimes it's good that it doesn't
crash. Other times it would at least be handy if it did.)

Thx,

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


Spot the invalid syntax

2018-03-08 Thread Ian Pilcher

(Because I certainly can't.)


def _san_dnsname_ips(dnsname, dnsname_is_cname=False):
"""
Returns a set of IP addresses, managed by this IPa instance,
that correspond to the DNS name (from the subjectAltName).

"""
fqdn = dnsutil.DNSName(dnsname).make_absolute()
if fqdn.__len__() < 4:
logger.debug("Skipping IPs for %s: hostname too short" % dnsname)
return ()
zone = dnsutil.DNSName(resolver.zone_for_name(fqdn))
name = fqdn.relativize(zone)
try:
result = api.Command['dnsrecord_show'](zone, name)['result']
except errors.NotFound as nf:
logger.debug("Skipping IPs for %s: %s" % (dnsname, nf))
return ()
ips = set()
for ip in itertools.chain(result.get('arecord', ()),
  result.get('record', ())):
if _ip_rdns_ok(ip, fqdn):
ips.add(ip)
cnames = result.get('cnamerecord', ())
if cnames:
if dnsname_is_cname:
logger.debug("Skipping IPs for %s: chained CNAME" % dnsname)
else:
for cname in cnames:
if not cname.endswith('.'):
cname = u'%s.%s' % (cname, zone)
ips.update(_san_dnsname_ips(cname, True)
return ips


2.7 and 3.6 are both giving me:

  File "/tmp/test.py", line 32
return ips
 ^
SyntaxError: invalid syntax

I've checked for tabs and mismatched parentheses.

Aargh!

--

Ian Pilcher arequip...@gmail.com
 "I grew up before Mark Zuckerberg invented friendship" 


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


Re: Spot the invalid syntax

2018-03-08 Thread Chris Angelico
On Fri, Mar 9, 2018 at 10:23 AM, Ian Pilcher  wrote:
> (Because I certainly can't.)
>
>> ips.update(_san_dnsname_ips(cname, True)
>> return ips
>
>
> 2.7 and 3.6 are both giving me:
>
>   File "/tmp/test.py", line 32
> return ips
>  ^
> SyntaxError: invalid syntax
>
> I've checked for tabs and mismatched parentheses.

Check the immediately preceding line (the one I quoted).

(Sometimes, you just need another pair of eyes.)

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


Re: Spot the invalid syntax

2018-03-08 Thread Ben Finney
Ian Pilcher  writes:

> > ips.update(_san_dnsname_ips(cname, True)
> > return ips
>
> 2.7 and 3.6 are both giving me:
>
>   File "/tmp/test.py", line 32
> return ips
>  ^
> SyntaxError: invalid syntax
>
> I've checked for tabs and mismatched parentheses.

Not sufficiently, it seems. Check the line preceding the ‘return’
statement.

Then, switch to using a programmer's text editor (I prefer Emacs) that
can spot these syntax errors while you type.

-- 
 \ “Nothing worth saying is inoffensive to everyone. Nothing worth |
  `\saying will fail to make you enemies. And nothing worth saying |
_o__)will not produce a confrontation.” —Johann Hari, 2011 |
Ben Finney

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


Re: Spot the invalid syntax

2018-03-08 Thread Ben Finney
Chris Angelico  writes:

> (Sometimes, you just need another pair of eyes.)

In many cases, those eyes can be virtual and non-human.

That's what syntax highlighting, and tools even more impressive (e.g.
linting tools that run continually), offer in a programmer's text
editor: a pair of eyes looking for mistakes while you type.

-- 
 \ “Giving every man a vote has no more made men wise and free |
  `\  than Christianity has made them good.” —Henry L. Mencken |
_o__)  |
Ben Finney

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


Re: Spot the invalid syntax

2018-03-08 Thread Chris Angelico
On Fri, Mar 9, 2018 at 10:33 AM, Ben Finney  wrote:
> Chris Angelico  writes:
>
>> (Sometimes, you just need another pair of eyes.)
>
> In many cases, those eyes can be virtual and non-human.
>
> That's what syntax highlighting, and tools even more impressive (e.g.
> linting tools that run continually), offer in a programmer's text
> editor: a pair of eyes looking for mistakes while you type.
>

Often true, but not always.

What would often be useful, but I've not usually (ever?) seen, is a
linter rule that continuation lines MUST be indented further than the
initial line. That would catch this problem, because the "return" line
is being misparsed as a continuation line, but it's indented far less.

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


Re: Spot the invalid syntax

2018-03-08 Thread Ben Finney
Chris Angelico  writes:

> On Fri, Mar 9, 2018 at 10:33 AM, Ben Finney  
> wrote:
> > In many cases, those eyes can be virtual and non-human.
> >
> > That's what syntax highlighting, and tools even more impressive
> > (e.g. linting tools that run continually), offer in a programmer's
> > text editor: a pair of eyes looking for mistakes while you type.
>
> Often true, but not always.

You mean the tool is not always looking for mistakes while you type?

If you mean that the tool doesn't catch all mistakes: of course not, and
I didn't imply it would. Are you saying that's a reason against using
such automated tools? (If not, I don't really understand what objection
you're making.)

Certainly it'd be good to always have a *perfect* overseer checking for
mistakes while one types. Until that happy day, though, let's use the
tools available to improve our code before even attempting to run it.

-- 
 \  “The fact that I have no remedy for all the sorrows of the |
  `\ world is no reason for my accepting yours. It simply supports |
_o__)  the strong probability that yours is a fake.” —Henry L. Mencken |
Ben Finney

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


Re: Spot the invalid syntax

2018-03-08 Thread Chris Angelico
On Fri, Mar 9, 2018 at 10:57 AM, Ben Finney  wrote:
> Chris Angelico  writes:
>
>> On Fri, Mar 9, 2018 at 10:33 AM, Ben Finney  
>> wrote:
>> > In many cases, those eyes can be virtual and non-human.
>> >
>> > That's what syntax highlighting, and tools even more impressive
>> > (e.g. linting tools that run continually), offer in a programmer's
>> > text editor: a pair of eyes looking for mistakes while you type.
>>
>> Often true, but not always.
>
> You mean the tool is not always looking for mistakes while you type?
>
> If you mean that the tool doesn't catch all mistakes: of course not, and
> I didn't imply it would. Are you saying that's a reason against using
> such automated tools? (If not, I don't really understand what objection
> you're making.)

LOL! Sorry, I derped a bit on the grammar there. Yes, I meant that you
can often catch those mistakes with your editor, but not always. There
are some errors that cannot possibly be caught by an editor, of
course; but there are others that theoretically could be, but I almost
never see them. That's the point I was raising - not really an
objection, but a segue into my next comment.

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


Re: Spot the invalid syntax

2018-03-08 Thread MRAB

On 2018-03-08 23:23, Ian Pilcher wrote:

(Because I certainly can't.)


def _san_dnsname_ips(dnsname, dnsname_is_cname=False):
"""
Returns a set of IP addresses, managed by this IPa instance,
that correspond to the DNS name (from the subjectAltName).

"""
fqdn = dnsutil.DNSName(dnsname).make_absolute()
if fqdn.__len__() < 4:
logger.debug("Skipping IPs for %s: hostname too short" % dnsname)
return ()
zone = dnsutil.DNSName(resolver.zone_for_name(fqdn))
name = fqdn.relativize(zone)
try:
result = api.Command['dnsrecord_show'](zone, name)['result']
except errors.NotFound as nf:
logger.debug("Skipping IPs for %s: %s" % (dnsname, nf))
return ()
ips = set()
for ip in itertools.chain(result.get('arecord', ()),
  result.get('record', ())):
if _ip_rdns_ok(ip, fqdn):
ips.add(ip)
cnames = result.get('cnamerecord', ())
if cnames:
if dnsname_is_cname:
logger.debug("Skipping IPs for %s: chained CNAME" % dnsname)
else:
for cname in cnames:
if not cname.endswith('.'):
cname = u'%s.%s' % (cname, zone)
ips.update(_san_dnsname_ips(cname, True)
return ips


2.7 and 3.6 are both giving me:

File "/tmp/test.py", line 32
  return ips
   ^
SyntaxError: invalid syntax

I've checked for tabs and mismatched parentheses.

Aargh!


Look closely at the preceding line. Count the parentheses.

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


Re: Spot the invalid syntax

2018-03-08 Thread Terry Reedy

On 3/8/2018 6:30 PM, Ben Finney wrote:

Ian Pilcher  writes:


 ips.update(_san_dnsname_ips(cname, True)

| <= auto-indent
If you type this code line in IDLE or other decent Python-aware code 
editor, the smart indent would put curser where I put the '|', thus 
indicating that there is no ')' matching the function call '('



 return ips


If you delete the helpful indent signal to type return here, ...



2.7 and 3.6 are both giving me:

   File "/tmp/test.py", line 32
 return ips
  ^
SyntaxError: invalid syntax

I've checked for tabs and mismatched parentheses.


IDLE, etc, flashes the ([{ opener for every )]} closer typed.
Not seeing an expected flash and seeing an unexpected indent catches 
most mismatches for me.



Not sufficiently, it seems. Check the line preceding the ‘return’
statement.

Then, switch to using a programmer's text editor (I prefer Emacs) that
can spot these syntax errors while you type.

I have never used Emacs, but I understand it has a decent Python-aware mode.

--
Terry Jan Reedy


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


Re: Spot the invalid syntax

2018-03-08 Thread Bob van der Poel
On Thu, Mar 8, 2018 at 4:23 PM, Ian Pilcher  wrote:

> (Because I certainly can't.)
>
> def _san_dnsname_ips(dnsname, dnsname_is_cname=False):
>> """
>> Returns a set of IP addresses, managed by this IPa instance,
>> that correspond to the DNS name (from the subjectAltName).
>>
>> """
>> fqdn = dnsutil.DNSName(dnsname).make_absolute()
>> if fqdn.__len__() < 4:
>> logger.debug("Skipping IPs for %s: hostname too short" % dnsname)
>> return ()
>> zone = dnsutil.DNSName(resolver.zone_for_name(fqdn))
>> name = fqdn.relativize(zone)
>> try:
>> result = api.Command['dnsrecord_show'](zone, name)['result']
>> except errors.NotFound as nf:
>> logger.debug("Skipping IPs for %s: %s" % (dnsname, nf))
>> return ()
>> ips = set()
>> for ip in itertools.chain(result.get('arecord', ()),
>>   result.get('record', ())):
>> if _ip_rdns_ok(ip, fqdn):
>> ips.add(ip)
>> cnames = result.get('cnamerecord', ())
>> if cnames:
>> if dnsname_is_cname:
>> logger.debug("Skipping IPs for %s: chained CNAME" % dnsname)
>> else:
>> for cname in cnames:
>> if not cname.endswith('.'):
>> cname = u'%s.%s' % (cname, zone)
>> ips.update(_san_dnsname_ips(cname, True)
>> return ips
>>
>
> 2.7 and 3.6 are both giving me:
>
>   File "/tmp/test.py", line 32
> return ips
>  ^
> SyntaxError: invalid syntax
>
> I've checked for tabs and mismatched parentheses.
>
> Aargh!
>
> Check the line before the error. Seems there may be a ')' missing :)


> --
> 
> Ian Pilcher arequip...@gmail.com
>  "I grew up before Mark Zuckerberg invented friendship" 
> 
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 

 Listen to my FREE CD at http://www.mellowood.ca/music/cedars 
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: b...@mellowood.ca
WWW:   http://www.mellowood.ca
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Spot the invalid syntax

2018-03-08 Thread Ian Pilcher

On 03/08/2018 05:26 PM, Chris Angelico wrote:

On Fri, Mar 9, 2018 at 10:23 AM, Ian Pilcher  wrote:

(Because I certainly can't.)


 ips.update(_san_dnsname_ips(cname, True)
 return ips

I've checked for tabs and mismatched parentheses.


Check the immediately preceding line (the one I quoted).

(Sometimes, you just need another pair of eyes.)



D'oh!

Clearly, my checking needs work.

Thanks mucho!

--

Ian Pilcher arequip...@gmail.com
 "I grew up before Mark Zuckerberg invented friendship" 


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


Re: Spot the invalid syntax

2018-03-08 Thread Ian Pilcher

On 03/08/2018 05:30 PM, Ben Finney wrote:

Not sufficiently, it seems. Check the line preceding the ‘return’
statement.


Indeed.  :-/


Then, switch to using a programmer's text editor (I prefer Emacs) that
can spot these syntax errors while you type.


The sad thing is that I am.  Just too bone-headed to use properly,
apparently.

--

Ian Pilcher arequip...@gmail.com
 "I grew up before Mark Zuckerberg invented friendship" 


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


Re: Spot the invalid syntax

2018-03-08 Thread MRAB

On 2018-03-08 23:57, Ben Finney wrote:

Chris Angelico  writes:


On Fri, Mar 9, 2018 at 10:33 AM, Ben Finney  wrote:
> In many cases, those eyes can be virtual and non-human.
>
> That's what syntax highlighting, and tools even more impressive
> (e.g. linting tools that run continually), offer in a programmer's
> text editor: a pair of eyes looking for mistakes while you type.

Often true, but not always.


You mean the tool is not always looking for mistakes while you type?

If you mean that the tool doesn't catch all mistakes: of course not, and
I didn't imply it would. Are you saying that's a reason against using
such automated tools? (If not, I don't really understand what objection
you're making.)

Certainly it'd be good to always have a *perfect* overseer checking for
mistakes . Until that happy day, though, let's use the
tools available to improve our code before even attempting to run it.


"... while one types"? I'm not so sure.

In the past I've used an IDE (not for Python) that, for example, 
underlined any identifiers that hadn't been defined, but found it 
annoying because it was indicating errors that were due to my not having 
finished writing yet!


Type, pause for thought, syntax error... yes, I know it's a syntax error 
at the moment, but I'm not finished!

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


Re: Unnoticed traceback in a thread (Posting On Python-List Prohibited)

2018-03-08 Thread Rob Gaddi

On 03/08/2018 05:06 PM, Lawrence D’Oliveiro wrote:

On Friday, March 9, 2018 at 11:43:00 AM UTC+13, Paul Rubin wrote:

That you're using threading.Lock for something like this is a borderline
code smell.


Any use of multithreading in non-CPU-intensive code is a code smell.



But CPU intensive code is exactly the circumstance where Python 
threading lets you down.  It really shines when you're I/O-bound.


--
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Which part of the loop is it going through in this class frame?

2018-03-08 Thread C W
Thank you guys, lots of great answers, very helpful. I got it!

A follow-up question:

How did the value of "object" get passed to "time"? Obviously, they have
different names. How did Python make that connection?

Code is below for convenience.

class Clock(object):
def __init__(self, time):
self.time = time
def print_time(self):
time = '6:30'
print(self.time)

clock = Clock('5:30')
clock.print_time()
5:30


Thank you!

On Thu, Mar 8, 2018 at 6:30 AM, Steven D'Aprano <
steve+comp.lang.pyt...@pearwood.info> wrote:

> On Wed, 07 Mar 2018 16:57:51 -0500, C W wrote:
>
> > Hello,
> >
> > I am new to OOP. I'm a bit confused about the following code.
> >
> > class Clock(object):
> > def __init__(self, time):
> > self.time = time
>
> Here you set the instance attribute "self.time".
>
> > def print_time(self):
> > time = '6:30'
> > print(self.time)
>
> Here you set the local variable "time", which is completely unrelated to
> the attribute "self.time".
>
> If you are used to languages where "foo" inside a method is a short-cut
> for "self.foo" or "this.foo", Python does not do that. Local variables
> and instance attributes are distinct concepts, and Python keeps them
> distinct.
>
>
> > How does line-by-line execution run inside a frame?
>
> There isn't actually line-by-line execution as such, although it can be
> very similar. Before the interpreter runs Python code, it compiles it to
> byte-code, and then runs the byte-code. A single line of source code
> could result in any number of lines of byte code, from zero to an
> unlimited number.
>
> > How does __init__
> > work? I understand you must have __init__.
>
> You understand wrongly then :-)
>
> It is normal and common to have an __init__ method, but it is not
> compulsory. If your class doesn't need one, you don't need to write it.
>
> The __init__ method is the initialiser. Think of it as very similar to
> the constructor in some other languages, and for now the differences
> aren't important. The usual purpose of the __init__ method is to
> initialise the instance and set any attributes needed.
>
> > Is it run before print_time(),
>
> The __init__ method is called once, when the instance is first created.
> So the short answer is, yes, it will run before print_time(). But only
> once.
>
> > if so, why don't I just set self.time = '6:30' instead of
> > self.time = time?
>
> Because then every instance will be set to 6:30, instead of letting you
> set each instance to a different time.
>
>
>
> --
> Steve
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


I am a student studying Python in Korea. I found strange thing while studying through idle

2018-03-08 Thread 노연수
If you type print (" hello\ rpython ") into the python 3.7.0.b2, only the 
python is printed and i learned it's a crystal. However, if you type print (" 
hello\ rpython ") in the python 3.7.0.b2 idle, it is output as hellopython. I 
wonder why it prints like this. I would appreciate your answer. 
 
I have attached the file so I would appreciate your reference. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Relationship between ‘object’ and the name of an object (was: Which part of the loop is it going through in this class frame?)

2018-03-08 Thread Ben Finney
C W  writes:

> A follow-up question:

(When you want to switch the discussion to a different subject, please
indicate that by changing the Subject field in your message.

I am not really clear on what you're asking, so I have guessed and made
a subject that I think summarises what you mean.)

> How did the value of "object" get passed to "time"? Obviously, they
> have different names. How did Python make that connection?

In the context of your original question, I think this one reveals that
you are missing some fundamental knowledge of how Python treats objects
and references.

Every object has a type. Types are themselves objects; the most basic
type, in Python, is named ‘object’.

Yes, already this makes it somewhat difficult to discuss these concepts
:-)

You will probably benefit greatly by reading and watching this
presentation by Ned Batchelder, that walks you through some common
minuderstandings, and replaces them with correct concepts for how Python
treats objects and references.

Facts and Myths about Names and Values
https://nedbatchelder.com/text/names1.html>

-- 
 \   “If you ever fall off the Sears Tower, just go real limp, |
  `\ because maybe you'll look like a dummy and people will try to |
_o__)catch you because, hey, free dummy.” —Jack Handey |
Ben Finney

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


Re: Futurize maps StringIO.StringIO to io.StringIO

2018-03-08 Thread Mark Lawrence

On 08/03/18 02:34, Skip Montanaro wrote:

I had some deja vu recently, cuz of this old thread:

https://mail.python.org/pipermail/python-list/2013-May/648245.html

Today the context is different, but the problem remains the same. One
of the futurize refactoring tools converts usage of StringIO.StringIO
to io.StringIO, which, given that the latter accepts just about
anything you through at it, is a bit surprising. Perhaps there is no
true corresponding class in the io module?

Skip



Maybe you need io.BytesIO?

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: I found strange thing while studying through idle

2018-03-08 Thread Ben Finney
Welcome, and congratulations on beginning with Python.

노연수 writes:

> If you type print (" hello\ rpython ") into the python 3.7.0.b2

I am not using Python 3.7 (it isn't released yet); I recommend staying
with the latest Python release. Today, that is version 3.6.

That difference in version should not make a difference to the ‘print’
behaviour, so I will assume your code behaves the same in Python 3.6.

When I use Python 3.6 and run the code example you give, it behaves this
way::

>>> print (" hello\ rpython ")
 hello\ rpython 

> only the python is printed and i learned it's a crystal.

(I don't understand that last clause; what crystal?)

The output above is what I expect. What do you expect?

> However, if you type print (" hello\ rpython ") in the python 3.7.0.b2
> idle, it is output as hellopython.

That's not what I see; the output in Idle version 3.6 is exactly the
same::

>>> print (" hello\ rpython ")
 hello\ rpython 

> I wonder why it prints like this.

So do I.

Please take the time to cut and paste *exactly* what program code is
being run, and *exactly* what text output you see.

Don't attempt to re-type it manually, because often that makes it
different in detail. One of the tricky things to learn in programming is
that small details can make a big difference!

> I have attached the file so I would appreciate your reference.

File attachments are unlikely to survive to most readers of this forum
(they get dropped, to reduce traffic size and spam and dangerous
attachments).

Instead, keep the program code short and simple; then, copy and paste it
exactly into the text body of your message. That's much more likely to
let us see exactly what you're seeing.

-- 
 \  “Better not take a dog on the space shuttle, because if he |
  `\   sticks his head out when you're coming home his face might burn |
_o__)up.” —Jack Handey |
Ben Finney

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


Re: Futurize maps StringIO.StringIO to io.StringIO

2018-03-08 Thread Skip Montanaro
Thanks. In one instance I used six.StringIO, which seems to work. The
question I had was more why futurize makes a transformation which is an
obvious semantic change.

Skip

On Thu, Mar 8, 2018, 7:55 PM Mark Lawrence  wrote:

> On 08/03/18 02:34, Skip Montanaro wrote:
> > I had some deja vu recently, cuz of this old thread:
> >
> > https://mail.python.org/pipermail/python-list/2013-May/648245.html
> >
> > Today the context is different, but the problem remains the same. One
> > of the futurize refactoring tools converts usage of StringIO.StringIO
> > to io.StringIO, which, given that the latter accepts just about
> > anything you through at it, is a bit surprising. Perhaps there is no
> > true corresponding class in the io module?
> >
> > Skip
> >
>
> Maybe you need io.BytesIO?
>
> --
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
>
> Mark Lawrence
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I found strange thing while studying through idle

2018-03-08 Thread Steven D'Aprano
I'm afraid the original post by 노연수 has not come 
through to me, so I will have to reply to Ben's reply.


On Fri, 09 Mar 2018 12:59:52 +1100, Ben Finney wrote:

> I am not using Python 3.7 (it isn't released yet); I recommend staying
> with the latest Python release. Today, that is version 3.6.

3.6 is the latest *stable* release; but there are unstable releases, such 
as 3.7.0.b2.

We should be glad that there are people willing to run unstable and beta 
versions, otherwise they would not get any real-world testing, bugs would 
not be fixed, and the "stable" X.Y.0 release would be a de-facto 
unstable, untried beta version.


> When I use Python 3.6 and run the code example you give, it behaves this
> way::
> 
> >>> print (" hello\ rpython ")
>  hello\ rpython

My guess is that the Original Poster carelessly re-typed his code instead 
of copying and pasting it. When he said he tried this:

print (" hello\ rpython ")

what he *actually* did was probably something like this:

print ("hello\rpython")

When I try that, I get this:

py> print ("hello \rpython")
python


which seems to match the OP's description.

Printing strings containing \r (carriage returns) may be dependent on the 
console or terminal you use, and even on *where* the carriage return is 
in the string, but in general I expect that printing \r will instruct the 
terminal to return to the beginning of the CURRENT line. The rest of the 
string will then overwrite the beginning of the line. For example:

py> print ("hello world\rpython")
pythonworld


>> However, if you type print (" hello\ rpython ") in the python 3.7.0.b2
>> idle, it is output as hellopython.

Again, my prediction is that the OP has carelessly retyped his code, and 
what he means is 

print ("hello \rpython")

which in IDLE *does not* return to the start of the line. 

In IDLE 3.5 on Linux, I get this:

>>> print('hello\rpython')
hello\rpython

Curiously, that's not a backslash r, it's actually a carriage return: 
when I copy and paste it in this text, the editor treated it as a new 
line character:

# direct copy and paste becomes this in my editor
>>> print('hello\rpython')
hello
python


But it is possible that due to differences between platforms, the OP's 
version of IDLE doesn't display a carriage return as \r but rather as an 
invisible zero-width space.



-- 
Steve

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


Re: I found strange thing while studying through idle

2018-03-08 Thread MRAB

On 2018-03-09 01:59, Ben Finney wrote:

Welcome, and congratulations on beginning with Python.

노연수 writes:


If you type print (" hello\ rpython ") into the python 3.7.0.b2


I am not using Python 3.7 (it isn't released yet); I recommend staying
with the latest Python release. Today, that is version 3.6.

That difference in version should not make a difference to the ‘print’
behaviour, so I will assume your code behaves the same in Python 3.6.

When I use Python 3.6 and run the code example you give, it behaves this
way::

 >>> print (" hello\ rpython ")
  hello\ rpython


only the python is printed and i learned it's a crystal.


(I don't understand that last clause; what crystal?)

The output above is what I expect. What do you expect?


However, if you type print (" hello\ rpython ") in the python 3.7.0.b2
idle, it is output as hellopython.


That's not what I see; the output in Idle version 3.6 is exactly the
same::

 >>> print (" hello\ rpython ")
  hello\ rpython


I wonder why it prints like this.


So do I.

Please take the time to cut and paste *exactly* what program code is
being run, and *exactly* what text output you see.

Don't attempt to re-type it manually, because often that makes it
different in detail. One of the tricky things to learn in programming is
that small details can make a big difference!


I have attached the file so I would appreciate your reference.


File attachments are unlikely to survive to most readers of this forum
(they get dropped, to reduce traffic size and spam and dangerous
attachments).

Instead, keep the program code short and simple; then, copy and paste it
exactly into the text body of your message. That's much more likely to
let us see exactly what you're seeing.


I think the line was actually:

print (" hello\rpython ")

and the question is why you get:

python

in a command prompt window, but:

hellopython

in IDLE.

(I also think that "crystal" is a translation error! Is it meant to be 
"control code"?)

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


Re: I found strange thing while studying through idle

2018-03-08 Thread MRAB

On 2018-03-09 03:57, Steven D'Aprano wrote:
[snip]


In IDLE 3.5 on Linux, I get this:


print('hello\rpython')

hello\rpython

Curiously, that's not a backslash r, it's actually a carriage return:
when I copy and paste it in this text, the editor treated it as a new
line character:

# direct copy and paste becomes this in my editor

print('hello\rpython')

hello
python


But it is possible that due to differences between platforms, the OP's
version of IDLE doesn't display a carriage return as \r but rather as an
invisible zero-width space.


IDLE 3.6 on Windows, it looks like this:

hellopython

but when I copy and paste it into an editor I get:

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


Re: Spot the invalid syntax

2018-03-08 Thread Steven D'Aprano
On Fri, 09 Mar 2018 00:47:21 +, MRAB wrote:

> On 2018-03-08 23:57, Ben Finney wrote:

>> You mean the tool is not always looking for mistakes while you type?
[...]
>> Certainly it'd be good to always have a *perfect* overseer checking for
>> mistakes . Until that happy day, though, let's use the tools available
>> to improve our code before even attempting to run it.
>> 
> "... while one types"? I'm not so sure.
> 
> In the past I've used an IDE (not for Python) that, for example,
> underlined any identifiers that hadn't been defined, but found it
> annoying because it was indicating errors that were due to my not having
> finished writing yet!

Aye, I find that error-checking while you type is a PITA. I tried using 
the Spyder IDE for a week or so, it was just so painful to use I couldn't 
keep going.

I'm not the world's fastest typest, so the fact that Spyder couldn't keep 
up with me was a serious black mark against it. There was visible lag 
between me typing and the characters showing up in the editor: I could 
type something like "for x in" before the "f" would appear.

Errors were highlighted in (I think?) red, and by displaying an icon next 
to the offending line. So as I would type, the screen would be constantly 
updated, slowly:

# me trying to type "print(mylist)"

p

pr # highlight in red and show the error icon

pri # highlight in red and show the error icon

prin  # highlight in red and show the error icon

print  # remove the highlighting and icon

print(  # display an error icon for missing parenthesis

print()  # okay, I'll type the paren first to keep the checker silent

print(m)

print(my)  # highlight the my in red and show the error icon

[skip a few more keystrokes]
print(mylist)  # finally remove the error highlighting


And because of the lag, it took about 15-20 seconds for the screen to 
update what took me 4-6 seconds to type.

This experience was so painful and unpleasant that it has permanently 
turned me off Spyder. I'd rather use Windows 95 Notepad.

 
> Type, pause for thought, syntax error... yes, I know it's a syntax error
> at the moment, but I'm not finished!

Not even "pause for thought".

I can *maybe* see the sense in checking each physical line once it is 
completed, but that's it. Or at least don't check words for mispellings 
until you have completed the token and started a new token, like your 
spell checker probably does. (The spell checker in this editor doesn't 
check for spelling errors until I hit the spacebar or Enter key, or use 
punctuation.)


-- 
Steve

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


Re: Which part of the loop is it going through in this class frame?

2018-03-08 Thread Steven D'Aprano
On Thu, 08 Mar 2018 20:25:42 -0500, C W wrote:

> Thank you guys, lots of great answers, very helpful. I got it!
> 
> A follow-up question:
> 
> How did the value of "object" get passed to "time"? Obviously, they have
> different names. How did Python make that connection?

It didn't. You have misunderstood what is happening. Let's go though it 
bit by bit:

> Code is below for convenience.
> 
> class Clock(object):

The "class" statement declares a new class, called "Clock", which 
inherits from the built-in class "object".

[Aside: some people describe "object" as a "type" rather than a class. 
There are some differences in meaning between type/class in computer 
science, and in Python 2 they are slightly different things, but in 
Python 3 you can consider class and type to be synonyms.]

So object is not a parameter, it is a superclass. This tells Python that 
your Clock class is a subclass of object.

> def __init__(self, time):
> self.time = time

The initialiser __init__ method is special, because it defines the 
signature for calling the class. So when you say:

clock = Clock("5:30")


Python creates a new Clock instance, and calls __init__ and passes "5:30" 
as the *time* parameter.

(I have glossed over some technical details and complexities.)

The thing to remember is that when you create a new instance by calling 
the class Clock(...), your arguments have to match the __init__ method.


-- 
Steve

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


Re: I found strange thing while studying through idle

2018-03-08 Thread Ben Finney
MRAB  writes:

> I think the line was actually […]
> (I also think that "crystal" is […]

Let's not get into the warrens of responding to what the OP *didn't*
write. we're in no hurry. I'd like to wait for clarification from the
original poster, and not guess what they meant.

-- 
 \   “The Vatican is not a state.… a state must have people. There |
  `\are no Vaticanians.… No-one gets born in the Vatican except by |
_o__)an unfortunate accident.” —Geoffrey Robertson, 2010-09-18 |
Ben Finney

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


Re: Module Issue

2018-03-08 Thread dieter
Abdur-Rahmaan Janhangeer  writes:
> i have a project at
>
> https://github.com/Abdur-rahmaanJ/honeybot
>
> see https://github.com/Abdur-rahmaanJ/honeybot/tree/master/honeybot
>
> my question is :
>
> how to include a util file / module that can be imported in both
> core_plugins and
> user_plugins?
>
> if that is too difficult, let us take only core_plugins
>
> make a module not found error not appear when running main.py

Have a look at so called "namespace package"s.

A "namespace package" is in some sense a "virtual package" consisting
of an extensible set of subpackages (real and
potentially other "namespace" packages).
The subpackages may declare dependencies on other subpackages
of the "namespace package" and thereby ensure, that the subset
they depend on are installed if they are installed.


"dm.zope.rpc" is an example for such a "namespace package".
It contains common (= cross protocol) RPC (= "Remote Procedure Call")
infrastructure (and some protocol plugins);
"dm.zope.rpc.wsdl_suds" is a subpackage providing support
for the SOAP/WSDL protocol (using "suds" as basic implementation
component).

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


Re: socket: Did I find a bug?

2018-03-08 Thread dieter
Antoon Pardon  writes:
> This is on a debian 9 box python 2.7.13
>
> My interpretation is that a timeout exception is thrown and that the
> args attribute of such an exception is an empty tuple which then causes
> an IndexError in line 482 of module /usr/lib/python2.7/socket.py. Does
> that soundplausible?

Yes -- however, usually the "args" tuple of an exception is not empty.

I am using the FTP class in Python 2.7 myself and I am quite
(though not completely) sure that I already have had timeouts in
my FTP interaction -- without seeing your problem.

Nevertheless, you might see a bug: there are two kinds of timeouts:
connection and read timeout. You are facing a read timeout (if
you see a timeout at all); while I likely saw connection timeouts.
However, the resulting timeout exception should in both cases
be identical with respect to the "args" tuple.

> Here is the traceback:
>
> Traceback (most recent call last):
> ...
>   File "/usr/local/lib/python-apps/rmtdump/ftputil.py", line 211, in open
> return ftpfile(ftp, fn, mode, True)
>   File "/usr/local/lib/python-apps/rmtdump/ftputil.py", line 70, in __init__
> self.cnct =  self.ftp.transfercmd("%s %s" % (cmd, rfn))
>   File "/usr/lib/python2.7/ftplib.py", line 376, in transfercmd
> return self.ntransfercmd(cmd, rest)[0]
>   File "/usr/lib/python2.7/ftplib.py", line 710, in ntransfercmd
> conn, size = FTP.ntransfercmd(self, cmd, rest)
>   File "/usr/lib/python2.7/ftplib.py", line 339, in ntransfercmd
> resp = self.sendcmd(cmd)
>   File "/usr/lib/python2.7/ftplib.py", line 249, in sendcmd
> return self.getresp()
>   File "/usr/lib/python2.7/ftplib.py", line 215, in getresp
> resp = self.getmultiline()
>   File "/usr/lib/python2.7/ftplib.py", line 201, in getmultiline
> line = self.getline()
>   File "/usr/lib/python2.7/ftplib.py", line 186, in getline
> line = self.file.readline(self.maxline + 1)
>   File "/usr/lib/python2.7/socket.py", line 482, in readline
> if e.args[0] == EINTR:
> IndexError: tuple index out of range

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


Re: Unnoticed traceback in a thread

2018-03-08 Thread dieter
Skip Montanaro  writes:

> I have a program which is almost always running in a single thread. It
> uses a daemon thread (via threading.Timer) to periodically checkpoint
> some state. The program runs for days at a time.
>
> Over the past couple days, two instances of the subthread croaked with
> tracebacks because while they were iterating over the checkpointable
> data, the main thread modified the data. Blammo! It was an easy fix
> (threading.Lock) and everything is back on an even keel.
>
> After the bug was tickled, the program continued to do its thing. It
> just stopped checkpointing. Given the way the program is managed, the
> traceback wound up in an obscure log file, and it was a couple days
> before I noticed it. I've seen this sort of
> thread-dies-but-program-doesn't-crash situation before. I can look at
> ways to more actively monitor the contents of the obscure log file,
> but is there some non-hackish way that the demise of the daemon thread
> can take down the entire program? (Sometimes it's good that it doesn't
> crash. Other times it would at least be handy if it did.)

I approach situations like this by running the thread function
inside a "try: ... except: ..." block. In the "except" handler,
I can then so whatever is necessary if the thread function has died
unexpectedly -- e.g. kill the complete process.

Concretely: instead of "start_new_thread(my_thread_function, ...)",
I use

def wrapped_thread_function(*args, **kw):
  try:
my_thread_function(*args, **kw)
  except:
... do whatever is necessary should "my_thread_function" fails ...

start_new_thread(wrapped_thread_function, ...)

Similar, should you use the "Thread" class (instead of "start_new_thread").

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