Re: repr = expression representation?

2019-05-17 Thread Christian Gollwitzer

Am 17.05.19 um 06:13 schrieb Stefan Ram:   However, look at this


|>>> print( str( print ))
|

|>>> print( repr( print ))
|

   . While it is nice that »str( print )« gives some useful
   information, I would expect »repr( print )« to give
   »print« - 


This is impossible. Python does not use "call by name", so a function 
cannot know how the argument is called in the upper stack level. Consider:



Apfelkiste:inotes chris$ python3
Python 3.6.1 |Anaconda 4.4.0 (x86_64)| (default, May 11 2017, 13:04:09)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> blafasel = print
>>> print(repr(blafasel))

>>>

You'll have to accept that not all Python objects can be represented as 
literals. While a user defined function /could/ be printed as a lambda, 
so expecting:


def test(x):
return 2*x

print(repr(test))

-> lambda x : 2*x

would be half-reasonable, it is impossible to print out the C source 
code of the built-in print function, unless one builds a JIT C compiler 
into Python.


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


EuroPython 2019: Sponsor brochure available

2019-05-17 Thread M.-A. Lemburg
We are pleased to present our EuroPython 2019 Sponsor Brochure:

  * https://ep2019.europython.eu/sponsor/brochure/ *

We have worked with our designer to compile all relevant information
about the conference in a nice to read brochure, you can use to
discuss a possible sponsorship in your company.

If you have questions, please contact our sponsor team at
[email protected].

Once you have decided, please sign up via the form on our sponsor
package page.

https://ep2019.europython.eu/sponsor/packages/


Early-bird sponsorship deal
---

If you are quick to decide, you can benefit from a 10% early-bird
discount we give on sponsor packages, if you sign up today (Friday,
May 17):

https://ep2019.europython.eu/sponsor/packages/



Dates and Venues


EuroPython will be held from July 8-14 2019 in Basel, Switzerland, at
the Congress Center Basel (BCC) for the main conference days (Wed-Fri)
and the FHNW Muttenz for the workshops/trainings/sprints days
(Mon-Tue, Sat-Sun).

For more details, please have a look at our website and the FAQ:

https://ep2019.europython.eu/faq


Help spread the word


Please help us spread this message by sharing it on your social
networks as widely as possible. Thank you !

Link to the blog post:

https://blog.europython.eu/post/184937371007/europython-2019-sponsor-brochure-available

Tweet:

https://twitter.com/europython/status/1129286303055568896


Enjoy,
--
EuroPython 2019 Team
https://ep2019.europython.eu/
https://www.europython-society.org/

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


Re: How to read barcoded value from PDF

2019-05-17 Thread damianleejob
在 2011年6月28日星期二 UTC+8下午5:30:21,Robin Becker写道:
> On 28/06/2011 06:59, Asif Jamadar wrote:
> > Hi,
> >
> ...
> >
> > In Reportlab I can do the following code to generate barcode and to get the 
> > value of that barcode
> >
> >
> >
> >  
> > barcode=code39.Extended39("123456789",barWidth=0.2*mm,barHeight=8*mm)
> >
> >
> >
> >  bc = Paragraph("Barcode value: %s" % barcode.value, 
> > STYLES['Normal'])
> >
> >
> >
> >  document.append(bc)
> >
> > But how can I achieve this from the existing PDF document??
> .
> 
> you might consider asking on the reportlab list as there is considerable 
> experience there about pdf in general.
> 
> It's unlikely that you will be able to easily discern which string/text in 
> the 
> pdf corresponds to the barcode values that you are interested in.
> 
> PDF does allow things called annotations which reportlab can generate.
> 
> Alternatively you can generate an invisible string which may make more sense 
> than the simple barcode value. So when you draw the barcode you also need to 
> add 
> the magic string using some prefix/postfix that allows easy extraction with 
> pypdf or similar eg
> 
> "===radamajfisa===123456789===radamajfisa===". Your text extractor should be 
> able to find this without too much trouble.
> -- 
> Robin Becker

You can check out this .net barcode reader for PDF document: 
http://www.barcodec.com/products/netpdfbarcodereader-all.html. It might be 
helpful.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: repr = expression representation?

2019-05-17 Thread Ben Bacarisse
Christian Gollwitzer  writes:

> Am 17.05.19 um 06:13 schrieb Stefan Ram:   However, look at this
>>
>> |>>> print( str( print ))
>> |
>>
>> |>>> print( repr( print ))
>> |
>>
>>. While it is nice that »str( print )« gives some useful
>>information, I would expect »repr( print )« to give
>>»print« - 
>
> This is impossible. Python does not use "call by name", so a function
> cannot know how the argument is called in the upper stack
> level. Consider:
>
> Apfelkiste:inotes chris$ python3
> Python 3.6.1 |Anaconda 4.4.0 (x86_64)| (default, May 11 2017, 13:04:09)
> [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
 blafasel = print
 print(repr(blafasel))
> 


I don't think that renaming is important to SR.  The result should be,
in his view, a string representing the /value/ of the argument to repr,
so repr(print) and replr(blafasel) could both return the same (as they
indeed do) thing and I think he'd be happy.

> You'll have to accept that not all Python objects can be represented
> as literals.

I don't think SR minds if the result is not a literal.  I think the hope
was simply that eval(repr(E)) === E for any expression E.  You could, in
a very limited way, fudge it like this:

def myrepr(e):
if isinstance(e, types.BuiltinFunctionType):
return e.__name__
return repr(e)

The trouble is that print does not always mean print because that
identifier can be rebound.  Python could try to provide some /other/
name for every object, one that can't be rebound (something like an
environment + string lookup) but it's probably not worth it.


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


About: Python not recognizing command even after installed Python 3.7.3

2019-05-17 Thread Jpn Jha
Dear Team
I have already installed python 3.7.3 64-bit  in my window 8.1.
I started learning Django using python. But after few days 4-5 days I found
python  not recognizing command.
Could you please advise me. Is there any possibilities of  Antivirous
update and
 running for removing virous .
Thanks
Regards
Jai Prakash
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Import module from a different subdirectory

2019-05-17 Thread Rich Shepard

On Fri, 17 May 2019, Inada Naoki wrote:


This is slightly off topic (not relating to your problem), but please
don't think "Python 3 doesn't require __init__.py for packages". It is
common misunderstanding.


Inada,

Actually, your response is on topic and probably the reason I have the
import problem.


Package directory without __init__.py is "namespace package".
Namespace package is not a regular package.  See [1] for detail.


Thank you for correcting me.

Regards,

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


Re: Import module from a different subdirectory

2019-05-17 Thread Rich Shepard

On Thu, 16 May 2019, Rich Shepard wrote:


The project directory contains subdirectories, including gui/ (with the
tkinter views) and classes/ with the SQLAlchemy model.py.


Getting closer, but still missing a piece of the solution.

First, I added __init__.py to each module subdirectory to specify that the
subdirectory is a package.

Second, in ~/.bash_profile I added two lines, the first is the project's
root directory:

PYTHONPATH=$HOME/development/bustrac
export PYTHONPATH

Testing this suggests that python is finding the path:

$ python3
Python 3.7.3 (default, Mar 26 2019, 06:40:28) 
[GCC 5.5.0] on linux

Type "help", "copyright", "credits" or "license" for more information.

import os
os.environ["PYTHONPATH"]

'/home/rshepard/development/bustrac'

but the import is still not working.

Do I need to specify each bustrac/ subdirectory in the PYTHONPATH? If not,
what am I still missing?

Regards,

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


subscribe

2019-05-17 Thread Matthias Weckbecker


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


Re: subscribe

2019-05-17 Thread Ethan Furman

You have been subscribed.  Welcome to Python List!

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


Re: Instance vs Class variable oddity

2019-05-17 Thread Irv Kalb

> On May 15, 2019, at 5:41 PM, Ben Finney  wrote:
> 
> Irv Kalb  writes:
> 
>> I just saw some code that confused me.  The confusion has to do with
>> class variables and instance variables.
> 
> (Perhaps unrelated, but here's another confusion you may be suffering
> from: There's no such thing as a “class variable” or “instance
> variable”. In Python, a “variable” is always a *binding* between a name
> and and object. The “variable” has no concept of different types.)
> 
>> 
> 
> I'm not sure I understand the confusion; once the instance has an
> attribute of that name, the same logic you outlined above applies when
> attempting to resolve that attribute. When ‘self.x’ exists on the
> instance, that's what will be used when resolving ‘self.x’.
> 
> I hope that helps.
> 

Thanks for your comments.  I am very aware of all the other issues that you 
explained. 

The only thing that threw me was that in a line like:

self.x = self.x + 1

in a method, these two uses of self.x can refer to different variables.  I 
actually teach Python, and this would be a very difficult thing to explain to 
students. 

I have never run across this issue because I would never use the same name as 
an instance attribute and a class attribute.  (I also know that "attribute" is 
the "official" terms, but I've called them instance variables and class 
variables for so many years (working in other languages), that I use those 
terms without thinking.)

Thanks,

Irv


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


Re: Instance vs Class variable oddity

2019-05-17 Thread Chris Angelico
On Sat, May 18, 2019 at 4:40 AM Irv Kalb  wrote:
>
> Thanks for your comments.  I am very aware of all the other issues that you 
> explained.
>
> The only thing that threw me was that in a line like:
>
> self.x = self.x + 1
>
> in a method, these two uses of self.x can refer to different variables.  I 
> actually teach Python, and this would be a very difficult thing to explain to 
> students.
>
> I have never run across this issue because I would never use the same name as 
> an instance attribute and a class attribute.  (I also know that "attribute" 
> is the "official" terms, but I've called them instance variables and class 
> variables for so many years (working in other languages), that I use those 
> terms without thinking.)
>

Yes, this is a little unusual. It's a consequence of the
run-time-lookup that defines attributes, as opposed to the
compile-time-lookup that defines most name bindings. For instance:

x = 0
def f():
print(x)
x = 1
print(x)

will raise UnboundLocalError, rather than printing zero followed by
one. But the global and builtin namespaces are looked up completely
dynamically:

class int(int): pass

This will look up the built-in "int" type, create a subclass, and make
that a global.

So this is uncommon, but not unique. Sometimes, if one thing doesn't
exist, you find another - even if it's going to exist a moment later.

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


Re: Instance vs Class variable oddity

2019-05-17 Thread Ethan Furman

On 05/17/2019 11:37 AM, Irv Kalb wrote:


self.x = self.x + 1

I have never run across this issue because I would never use the same name as 
an instance attribute and a class attribute.


So you treat your class attributes as if they were static?

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


Re: Instance vs Class variable oddity

2019-05-17 Thread jfong
Correct me if I am wrong, please.

I always think that the LEGB rule (e.g. the namespace to look up for) was 
applied at compile-time, only the binding was resolved "dynamically" at 
run-time. For example:

def foo():
print(x)

foo() will cause a NameError. But after

x = 5

foo() will run correctly.

I also don't think the term "variable" and "attribute" can be used 
exchangeable. Variable apply to an unbound name, and attribute applies to 
bounded name. For example:

foo.x = 3 will create an attribute x of function foo. It's either not a local 
variable, or a global variable. It's more likely a class instance attribute, 
and it's resolved by applying MRO rule dynamically.

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


Re: Import module from a different subdirectory

2019-05-17 Thread dieter
Rich Shepard  writes:
>> The project directory contains subdirectories, including gui/ (with the
>> tkinter views) and classes/ with the SQLAlchemy model.py.
> ...
> Second, in ~/.bash_profile I added two lines, the first is the project's
> root directory:
>
> PYTHONPATH=$HOME/development/bustrac
> export PYTHONPATH
>
> Testing this suggests that python is finding the path:
>
> $ python3
> Python 3.7.3 (default, Mar 26 2019, 06:40:28) [GCC 5.5.0] on linux
> Type "help", "copyright", "credits" or "license" for more information.
 import os
 os.environ["PYTHONPATH"]
> '/home/rshepard/development/bustrac'

Test this by looking at "sys.path" instead:

>>> import sys
>>> sys.path

It is "sys.path" which actually controls the import machinery.

> ...
> Do I need to specify each bustrac/ subdirectory in the PYTHONPATH? If not,
> what am I still missing?

This depends on how you make the import.

"sys.path" is typically a sequence of folders. Python's
import machinery will look in those folders for modules/paackages for its
(absolute) imports.
Thus, if you use "import " or "from  import ...",
then one of those folders should contain a module or package
named "".

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


Re: Instance vs Class variable oddity

2019-05-17 Thread dieter
Irv Kalb  writes:
> ...
> The only thing that threw me was that in a line like:
>
> self.x = self.x + 1
>
> in a method, these two uses of self.x can refer to different variables.  I 
> actually teach Python, and this would be a very difficult thing to explain to 
> students. 
>
> I have never run across this issue because I would never use the same name as 
> an instance attribute and a class attribute.

I use this regularly.

Think of the "class attribute" as providing a default for
a potential "instance attribute" of the same name.

In Python, almost everything from a class can be overridden
by the instance (exceptions: some special methods, descriptors).
Thus, one can (almost) view a class as a defaults provider for
its instances. Class attributes are just one case.

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