Re: Unicode filenames

2019-12-07 Thread Peter Otten
Bob van der Poel wrote:

> I have some files which came off the net with, I'm assuming, unicode
> characters in the names. I have a very short program which takes the
> filename and puts into an emacs buffer, and then lets me add information
> to that new file (it's a poor man's DB).
> 
> Next, I can look up text in the file and open the saved filename.
> Everything works great until I hit those darn unicode filenames.
> 
> Just to confuse me even more, the error seems to be coming from a bit of
> tkinter code:
>  if sresults.has_key(textAtCursor):
> bookname = os.path.expanduser(sresults[textAtCursor].strip())
> 
> which generates
> 
>   UnicodeWarning: Unicode equal comparison failed to convert both
>   arguments
> to Unicode - interpreting them as being unequal  if
> sresults.has_key(textAtCursor):
> 
> I really don't understand the business about "both arguments". Not sure
> how to proceed here. Hoping for a guideline!

I cannot provoke the error with dict.has_key() over here, only with direct 
comparisons:

>>> u"a" == u"ä"
False
>>> u"a" == "ä"
__main__:1: UnicodeWarning: Unicode equal comparison failed to convert both 
arguments to Unicode - interpreting them as being unequal
False

The problem is that you are mixing strings of type str and type unicode, and 
generally speaking the remedy is to use unicode throughout. In your case
this means opening files with io.open() or codecs.open() instead of the 
builtin, and invoking os.listdir() with a unicode argument.

I don't remember about Tkinter, I think it provides ascii-only strings as 
str and everything else as unicode. If that's correct you could play it safe 
with a conversion function:

def ensure_unicode(s):
if isinstance(s, bytes):
return s.decode("ascii")
return s

Your other option is to live with the *warning* -- it's not an error, just a 
reminder that you have to rethink your types once you switch to Python 3.

You can also switch off the message with

python -W ignore::UnicodeWarning yourscript

or by setting the PYTHONWARNINGS environment variable.


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


Re: Zipapp can't find sqlite db

2019-12-07 Thread dieter
Abdur-Rahmaan Janhangeer  writes:
> I'm using zipapp to include a gui + db
>
> __main__.py
> dbs/
> file.db
>
> When packaging, the db is there. When querying through sqlalchemy, it says
> can't open db file. Help appreciated!

I am unsure what you mean with "packaging". If you mean
"create a package for PyPI management", then data files
(unlike Python source code files) need special treatment.
In this case, read the documentation for your packageing tool.

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


Vim settings for Python (was: tab replace to space 4)

2019-12-07 Thread Peter J. Holzer
On 2019-11-29 13:46:38 +0900, 황병희 wrote:
> usally i write python code in gnu emacs on ubuntu 18.04 sometimes i
> re-edit the code vim in same machine so often when i do run the code in
> shell like as ./test.py i meet consol error -- which line wrong!
> 
> so i am considering how can i replace all tab to space 4 within python

As an aside, to prevent vim from inserting tabs in the first place, set
expandtab
sw=4
and maybe also
ts=4
(The latter is very much a matter of taste. I don't unless I have to
edit code which already contains tabs intended to be at a certain width.)

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Vim settings for Python (was: tab replace to space 4)

2019-12-07 Thread Bev In TX

> On Dec 7, 2019, at 4:16 AM, Peter J. Holzer  wrote:
> 
> As an aside, to prevent vim from inserting tabs in the first place, set
>expandtab
>sw=4
> and maybe also
>ts=4
> (The latter is very much a matter of taste. I don't unless I have to
> edit code which already contains tabs intended to be at a certain width.)

I’m not the OP, but I do appreciate this info.  Thanks!
Bev in TX
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Error getting data from website

2019-12-07 Thread Peter Otten
Michael Torrie wrote:

> On 12/6/19 5:31 PM, DL Neil via Python-list wrote:
>> If you read the HTML data that the REPL has happily splattered all over
>> your terminal's screen (scroll back) (NB "soup" is easier to read than
>> is "content"!) you will observe that what you saw in your web-browser is
>> not what Amazon served in response to the Python "requests.get()"!
> 
> Sadly it's likely that Amazon's page is largely built from javascript.

That's not the problem here. Quoting the html returned by

requests.get("https://www.amazon.ca/dp/B07RZFQ6HC";)

"""
To discuss automated access to Amazon data please contact api-services-
supp...@amazon.com.
"""

If you retrieve the page manually:

$ wget "https://www.amazon.ca/dp/B07RZFQ6HC"; -O tmp.gz
[...]
2019-12-07 11:47:03 (80,6 KB/s) - »tmp.gz« gespeichert [115426]

$ gunzip tmp.gz
$ python3
[...]
Type "help", "copyright", "credits" or "license" for more information.
>>> from bs4 import BeautifulSoup
>>> soup = BeautifulSoup(open("tmp").read())
>>> soup.find("span", dict(id="priceblock_dealprice")
... )
CDN$ 1,019.00
>>> _.text
'CDN$\xa01,019.00'

> So scraping static html is probably not going to get you where you want
> to go.  

... because Amazon doesn' like what you do. You can cheat or play by their 
rules and use the API.

> There are heavier tools, such as Selenium that uses a real
> browser to grab a page, and the result of that you can parse and search
> perhaps.



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


Re: array and struct 64-bit Linux change in behavior Python 3.7 and 2.7

2019-12-07 Thread Peter J. Holzer
On 2019-12-05 09:27:43 +, Barry Scott wrote:
> On 3 Dec 2019, at 01:50, Richard Damon  wrote:
> > On 12/2/19 4:25 PM, Barry Scott wrote:
> > x=struct.pack('L',0x102030405)
> > x
> >> b'\x05\x04\x03\x02\x01\x00\x00\x00'
> >> 
> >> Given I have exact control with b, h, i, and q but L is not fixed
> >> in size I'm not sure how it can be used with certainty across OS
> >> and versions.
> >> 
> >> Barry
> >> 
> > Actually, you DON'T have exact control with those sizes, it just happens
> > that all the platforms you are using happen to have the same size for
> > those types.
> 
> According to the docs for struct (python 2.7 and python 3.8) I do have
> exact control for the types I listed.

You also have exact control over the size of the 'L' type.

But only if you use the prefixes with a standard size (see the table in
https://docs.python.org/3/library/struct.html#byte-order-size-and-alignment),
not with "@" (which is the default). 

This is also true for the other sizes. A platform where short is 32 bits
or int is 64 bits might exist (in fact I've used the former (not with
Python, though), and while I've never used the latter, I've certainly
heard of one machine where that was the case (the Cray was quite famous
in its time)).

When you are reading and writing files which "can be used with certainty
across OS and versions" you need to use one of the prefixes "<", ">" or
"!" anyway because you also want to control the byte order, not just the
size (although big-endian architectures may be history in a few years).

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: array and struct 64-bit Linux change in behavior Python 3.7 and 2.7

2019-12-07 Thread Peter J. Holzer
On 2019-12-02 09:55:16 -0800, Rob Gaddi wrote:
> The struct situation is, as you said, a bit different.  I believe that with
> the default native alignment @, you're seeing 4-byte data padded to an
> 8-byte alignment, not 8-byte data.

Nope. That's really an 8 byte long:

Python 3.7.3 (default, Apr  3 2019, 05:39:12)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import struct

>>> struct.pack('L', 0x0807060504030201)
b'\x01\x02\x03\x04\x05\x06\x07\x08'

All 8 bytes are serialized. Trying to serialize 9 bytes (actually only 68
non-zero bits) fails:

>>> struct.pack('L', 0x090807060504030201)
Traceback (most recent call last):
  File "", line 1, in 
struct.error: argument out of range

And when you use the "standard size", 8 bytes are also too much:

>>> struct.pack('=L', 0x0807060504030201)
Traceback (most recent call last):
  File "", line 1, in 
struct.error: 'L' format requires 0 <= number <= 4294967295

But 4 bytes are ok:
>>> struct.pack('=L', 0x04030201)
b'\x01\x02\x03\x04'


hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Zipapp can't find sqlite db

2019-12-07 Thread Barry Scott



> On 7 Dec 2019, at 10:07, dieter  wrote:
> 
> Abdur-Rahmaan Janhangeer  writes:
>> I'm using zipapp to include a gui + db
>> 
>> __main__.py
>> dbs/
>>file.db
>> 
>> When packaging, the db is there. When querying through sqlalchemy, it says
>> can't open db file. Help appreciated!
> 
> I am unsure what you mean with "packaging". If you mean
> "create a package for PyPI management", then data files
> (unlike Python source code files) need special treatment.
> In this case, read the documentation for your packageing tool.


zipapp is part of the python standard library.

The docs only talk about packaging pure python code, not data files.

Barry

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


Re: Unicode filenames

2019-12-07 Thread Barry Scott



> On 6 Dec 2019, at 18:17, Bob van der Poel  wrote:
> 
> I have some files which came off the net with, I'm assuming, unicode
> characters in the names. I have a very short program which takes the
> filename and puts into an emacs buffer, and then lets me add information to
> that new file (it's a poor man's DB).
> 
> Next, I can look up text in the file and open the saved filename.
> Everything works great until I hit those darn unicode filenames.

Yes the names you download are unicode.
All OS can save that filename to disk these days.
Can you see the file on disk with the name you expect?

What OS are you using? 

> 
> Just to confuse me even more, the error seems to be coming from a bit of
> tkinter code:
> if sresults.has_key(textAtCursor):
>bookname = os.path.expanduser(sresults[textAtCursor].strip())
> 
> which generates
> 
>  UnicodeWarning: Unicode equal comparison failed to convert both arguments
> to Unicode - interpreting them as being unequal  if
> sresults.has_key(textAtCursor):

What version of python are you using? Peter only managed to get the error
with python 2. 

Do you get the error with python 3?

Barry


> I really don't understand the business about "both arguments". Not sure how
> to proceed here. Hoping for a guideline!
> 
> Thanks.
> 
> 
> -- 
> 
>  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
> 

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


JavaScript Calculator Program

2019-12-07 Thread ferzan saglam
Hi People, I am working on a simple calculator which uses operands (+-*/).
The program allows me to choose an operand and enter the first two values, but 
when it gets to doing the maths, it gives me an error on 
"console.log ("The result is ", res);" under the + operand.
(error code reads: Println is not a function)

Any help will be much appreciated. 
Thanks in advance.

---

console.log ("1. Add numbers"); 

console.log("2. Subtract numbers"); 

console.log("3. Multiply numbers"); 

console.log("4. Divide numbers");   


console.log = prompt("What's your choice?");


var num1 = prompt("Enter the first number ");   

firstnumber = prompt;   

var num2 = prompt("Enter the second number ");  

secondnumber = prompt;  

var choice; 
var res;

if (choice == 1);   
result = (num1 + num2); 

console.log ("The result is ", res);


if (choice == 2);   
result = (num1 - num2); 

console.log ("The result is = ", res);  


if (choice == 3);   
result = (num1 * num2); 

console.log ("The result is = ", res);  


if (choice == 4);   
result = (num1 / num2); 

console.log ("The result is = ", res);

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


Re: JavaScript Calculator Program

2019-12-07 Thread Chris Angelico
On Sat, Dec 7, 2019 at 11:21 PM ferzan saglam  wrote:
>
> Hi People, I am working on a simple calculator which uses operands (+-*/).
> The program allows me to choose an operand and enter the first two values, 
> but when it gets to doing the maths, it gives me an error on
> "console.log ("The result is ", res);" under the + operand.
> (error code reads: Println is not a function)
>
> Any help will be much appreciated.
> Thanks in advance.

Do your own homework.

You've just posted a JavaScript homework problem to a Python mailing
list. The only help I'm going to give you is to remind you to read
your error messages, because they are there to help you.

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


Re: ImportError: No module named Adafruit_SSD1306 Update

2019-12-07 Thread Peter J. Holzer
On 2019-12-05 19:30:31 +, Rhodri James wrote:
> On 05/12/2019 18:49, RobH wrote:
> > TabError: inconsistent use of tabs and spaces in indentation
> 
> The problem will be that you have a mix of tabs and spaces in your
> indentation.  This causes problems because some people don't think that the
> One True Tab Width is 8 characters ;-) so to them the indentation looks
> ragged.  Worse, when they mix tabs and spaces, code that looks to be at the
> same indentation level to them looks different to the interpreter.  The
> decision was taken a while ago that Python should put its foot down about
> this, and demand that we use either all tabs or all spaces for our
> indentation.

At least as of Python 3.7, this is not true: You can mix spaces and tabs
in the same line. The mix just has to be consistent between lines. So
for example:

  1 #!/usr/bin/python3
  2 
  3 def f(a, b, c):
  4 if a < b:
  5 »···if b < c:
  6 »···print("x")
  7 »···else:
  8 »···print("y")

(I have configured vim to display a tab as a right guillemet followed by
middle dots and simply pasted that into this message)

produces the error message:

  File "./indent3", line 5
if b < c:
^
TabError: inconsistent use of tabs and spaces in indentation

because depending on the tab width line 5 might be more or less indented
than line 4.

(I don't actually understand the rules here: I constructed a very
similar example before that the same python interpreter accepted.)

However, this works:

  1 #!/usr/bin/python3
  2
  3 def f(a, b, c):
  4 if a < b:
  5 »···if b < c:
  6 »···print("x")
  7 »···else:
  8 »···print("y")


I would recommend to avoid that and stick to either tabs or spaces
(personally, I prefer spaces). You might want to use an editor which
can display tabs specially (like vim).

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Vim settings for Python

2019-12-07 Thread 황병희
Hello Peter^^^

> As an aside, to prevent vim from inserting tabs in the first place, set
> expandtab
> sw=4
> and maybe also
> ts=4
> (The latter is very much a matter of taste. I don't unless I have to
> edit code which already contains tabs intended to be at a certain width.)

Because sometimes, i use vim (Ubuntu 18.04 LTS), so very much thanks^^^

Sincerely,

-- 
^고맙습니다 _地平天成_ 감사합니다_^))//
-- 
https://mail.python.org/mailman/listinfo/python-list


IOError: cannot open resource

2019-12-07 Thread RobH
When I run a python project with an oled display on a rasperry pi zero, 
it calls for the Minecraftia.ttf font. I have the said file in 
home/pi/.fonts/


I get this error:

pi@raspberrypi:~/Downloads $ python interdisplay.py
Traceback (most recent call last):
  File "interdisplay.py", line 220, in 
display_time()
  File "interdisplay.py", line 26, in display_time
font = ImageFont.truetype('home/pi/.fonts/Minecraftia.ttf', 35)
  File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 280, 
in truetype

return FreeTypeFont(font, size, index, encoding, layout_engine)
  File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 145, 
in __init__

layout_engine=layout_engine)
IOError: cannot open resource

PILLOW version forked from PIL 1.1.7

I have no idea to what to do about this.

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


Re: IOError: cannot open resource

2019-12-07 Thread Peter Otten
RobH wrote:

> When I run a python project with an oled display on a rasperry pi zero,
> it calls for the Minecraftia.ttf font. I have the said file in
> home/pi/.fonts/
> 
> I get this error:
> 
> pi@raspberrypi:~/Downloads $ python interdisplay.py
> Traceback (most recent call last):
>File "interdisplay.py", line 220, in 
>  display_time()
>File "interdisplay.py", line 26, in display_time
>  font = ImageFont.truetype('home/pi/.fonts/Minecraftia.ttf', 35)
>File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 280,
> in truetype
>  return FreeTypeFont(font, size, index, encoding, layout_engine)
>File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 145,
> in __init__
>  layout_engine=layout_engine)
> IOError: cannot open resource
> 
> PILLOW version forked from PIL 1.1.7
> 
> I have no idea to what to do about this.

You don't have the font "Minecraftia.ttf". You can either try to find and 
install it or replace it with another that you already have in the 
/home/pi/.fonts directory.

You may even lie about it, e. g. assuming there is a font called 
"NotoSerif-Regular.ttf"

$ cd /home/pi/.fonts
$ ln NotoSerif-Regular.ttf Minecraftia.ttf

should fix the error without making changes to the code.

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


Re: IOError: cannot open resource

2019-12-07 Thread Dan Sommers

On 12/7/19 9:43 AM, RobH wrote:

When I run a python project with an oled display on a rasperry pi zero,
it calls for the Minecraftia.ttf font. I have the said file in
home/pi/.fonts/


Do you mean /home/pi/.fonts (with a leading slash, an absolute path
rather than a relative one)?

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


Re: Error getting data from website

2019-12-07 Thread Michael Torrie
On 12/7/19 3:53 AM, Peter Otten wrote:
> 
> ... because Amazon doesn' like what you do. You can cheat or play by their 
> rules and use the API.

Yup and although I have no love for Amazon, I can understand why they
don't want bots on the site. Already they have enough trouble with bots
buying up merchandise that gets resold on the grey market later.  And
also fake reviews.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: IOError: cannot open resource

2019-12-07 Thread RobH

On 07/12/2019 16:04, Peter Otten wrote:

RobH wrote:


When I run a python project with an oled display on a rasperry pi zero,
it calls for the Minecraftia.ttf font. I have the said file in
home/pi/.fonts/

I get this error:

pi@raspberrypi:~/Downloads $ python interdisplay.py
Traceback (most recent call last):
File "interdisplay.py", line 220, in 
  display_time()
File "interdisplay.py", line 26, in display_time
  font = ImageFont.truetype('home/pi/.fonts/Minecraftia.ttf', 35)
File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 280,
in truetype
  return FreeTypeFont(font, size, index, encoding, layout_engine)
File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 145,
in __init__
  layout_engine=layout_engine)
IOError: cannot open resource

PILLOW version forked from PIL 1.1.7

I have no idea to what to do about this.


You don't have the font "Minecraftia.ttf". You can either try to find and
install it or replace it with another that you already have in the
/home/pi/.fonts directory.

You may even lie about it, e. g. assuming there is a font called
"NotoSerif-Regular.ttf"

$ cd /home/pi/.fonts
$ ln NotoSerif-Regular.ttf Minecraftia.ttf

should fix the error without making changes to the code.



Thanks for that.
I actually replaced Minecraftia.ttf in the code for 
NotoSerif-Regular.ttf, after I put that font in the .font folder.

It now runs without the above errors.

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


Re: IOError: cannot open resource

2019-12-07 Thread RobH

On 07/12/2019 16:00, Dan Sommers wrote:

On 12/7/19 9:43 AM, RobH wrote:

When I run a python project with an oled display on a rasperry pi zero,
it calls for the Minecraftia.ttf font. I have the said file in
home/pi/.fonts/


Do you mean /home/pi/.fonts (with a leading slash, an absolute path
rather than a relative one)?

Dan


Not sure how you mean, but it is just as I typed it, with a forward or 
leading slash.

I have it solved now, with a different font.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Unicode filenames

2019-12-07 Thread Bob van der Poel
On Sat, Dec 7, 2019 at 4:00 AM Barry Scott  wrote:

>
>
> > On 6 Dec 2019, at 18:17, Bob van der Poel  wrote:
> >
> > I have some files which came off the net with, I'm assuming, unicode
> > characters in the names. I have a very short program which takes the
> > filename and puts into an emacs buffer, and then lets me add information
> to
> > that new file (it's a poor man's DB).
> >
> > Next, I can look up text in the file and open the saved filename.
> > Everything works great until I hit those darn unicode filenames.
>
> Yes the names you download are unicode.
> All OS can save that filename to disk these days.
> Can you see the file on disk with the name you expect?
>
> What OS are you using?
>
> >
> > Just to confuse me even more, the error seems to be coming from a bit of
> > tkinter code:
> > if sresults.has_key(textAtCursor):
> >bookname = os.path.expanduser(sresults[textAtCursor].strip())
> >
> > which generates
> >
> >  UnicodeWarning: Unicode equal comparison failed to convert both
> arguments
> > to Unicode - interpreting them as being unequal  if
> > sresults.has_key(textAtCursor):
>
> What version of python are you using? Peter only managed to get the error
> with python 2.
>
> Do you get the error with python 3?
>
>
I'm running this program on Linux (Ubuntu 19.10) and Python2.

>
>
> > I really don't understand the business about "both arguments". Not sure
> how
> > to proceed here. Hoping for a guideline!
>
>
I've taking the coward's way out and renamed the 1/2 dozen files. Seems
that it is when I grab a filename from the DB it is in unicode and the the
textAtCursor() and then I am trying to open that file using a fork to a
pdf-display program. This is all Q&D stuff so I'm going to file it under
"mysteries of life" and live with it :)

Thanks all!

-- 

 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: IOError: cannot open resource

2019-12-07 Thread Michael Torrie
On 12/7/19 9:48 AM, RobH wrote:
> On 07/12/2019 16:00, Dan Sommers wrote:
>> On 12/7/19 9:43 AM, RobH wrote:
>>> When I run a python project with an oled display on a rasperry pi zero,
>>> it calls for the Minecraftia.ttf font. I have the said file in
>>> home/pi/.fonts/
>>
>> Do you mean /home/pi/.fonts (with a leading slash, an absolute path
>> rather than a relative one)?
>>
>> Dan
> 
> Not sure how you mean, but it is just as I typed it, with a forward or 
> leading slash.
> I have it solved now, with a different font.

What he means is that according to the stack trace you were asking for:
   home/pi/.fonts/Minecraftia.ttf

instead of
   /home/pi/.fonts/Minecraftia.ttf

If you cut and paste the traceback then that is what happened.  Likely
when you tried a different font you added the missing / and all was well.

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


Re: IOError: cannot open resource

2019-12-07 Thread RobH

On 07/12/2019 16:58, Michael Torrie wrote:

On 12/7/19 9:48 AM, RobH wrote:

On 07/12/2019 16:00, Dan Sommers wrote:

On 12/7/19 9:43 AM, RobH wrote:

When I run a python project with an oled display on a rasperry pi zero,
it calls for the Minecraftia.ttf font. I have the said file in
home/pi/.fonts/


Do you mean /home/pi/.fonts (with a leading slash, an absolute path
rather than a relative one)?

Dan


Not sure how you mean, but it is just as I typed it, with a forward or
leading slash.
I have it solved now, with a different font.


What he means is that according to the stack trace you were asking for:
home/pi/.fonts/Minecraftia.ttf

instead of
/home/pi/.fonts/Minecraftia.ttf

If you cut and paste the traceback then that is what happened.  Likely
when you tried a different font you added the missing / and all was well.



Yes that is correct, my mistake.

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


stuck on time

2019-12-07 Thread RobH

I am trying to do this project on a pi zero:

http://frederickvandenbosch.be/?p=1365

After overcoming a few errors, I now have the display working and the 
start of the code showing on the display, that being the time.


It doesn't move on to the next part of the code ie, no rectangle drawn
def display_time():
# Collect current time and date
if(time_format):
current_time = time.strftime("%I:%M")<<< stays at this line
else:
current_time = time.strftime("%H:%M")

current_date = time.strftime("%d/%m/%Y")

# Clear image buffer by drawing a black filled box
draw.rectangle((0,0,width,height), outline=0, fill=0

In the original code you can see that the author used the 
Minecraftia.ttf font, but I had to download the Minecraftia-Regular.ttf 
font. The link the author gave took me to that.


The Minecraft-Regular.ttf font produced errors when the code was run, 
saying at the end of the error that it cannot open resource.


I then used the NotoSerif-Regular.ttf font which let the code start 
without error, but as above it is stuck at the time.

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


Re: stuck on time

2019-12-07 Thread Karsten Hilbert
On Sat, Dec 07, 2019 at 05:48:00PM +, RobH wrote:

What happens if your run this line:

>   current_time = time.strftime("%I:%M")<<< stays at this line

in an interactive Python interpreter ?

(after you define "time" appropriately)

Karsten
--
GPG  40BE 5B0E C98E 1713 AFA6  5BC0 3BEA AC80 7D4F C89B
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Developers are advised to purge these malicious packages

2019-12-07 Thread David Lowry-Duda
On Wed, Dec 04, 2019 at 07:17:58PM +0100, Christian Heimes wrote:
> 
> At least the first pages are packaging files for Debian, Fedora, and
> other Linux distributions. Downstream distributions provide a Python
>
> 
> 
> Attackers abuse the fact and try to typo-squat packages in hope that
> somebody uses the Linux distribution package name "python3-dateutil"
> instead of the upstream name "python-dateutil" in requirements.txt

Yes, I understand. Thank you.

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


SQLObject 3.8.0

2019-12-07 Thread Oleg Broytman
Hello!

I'm pleased to announce version 3.8.0, the first stable release of branch
3.8 of SQLObject.


What's new in SQLObject
===

Features


* Add driver ``supersqlite``. Not all tests are passing
  so the driver isn't added to the list of default drivers.

Minor features
--

* Improve sqlrepr'ing ``ALL/ANY/SOME()``: always put the expression
  at the right side of the comparison operation.

Bug fixes
-

* Fixed a bug in cascade deletion/nullification.

* Fixed a bug in ``PostgresConnection.columnsFromSchema``:
  PostgreSQL 12 removed outdated catalog attribute
  ``pg_catalog.pg_attrdef.adsrc``.

* Fixed a bug working with microseconds in Time columns.

CI
--

* Run tests with Python 3.8 at Travis CI.

Contributors for this release are Andrew Trusty, Marco Sirabella and darix.

For a more complete list, please see the news:
http://sqlobject.org/News.html


What is SQLObject
=

SQLObject is an object-relational mapper.  Your database tables are described
as classes, and rows are instances of those classes.  SQLObject is meant to be
easy to use and quick to get started with.

SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite,
Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB).

Python 2.7 or 3.4+ is required.


Where is SQLObject
==

Site:
http://sqlobject.org

Development:
http://sqlobject.org/devel/

Mailing list:
https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss

Download:
https://pypi.org/project/SQLObject/3.8.0

News and changes:
http://sqlobject.org/News.html

StackOverflow:
https://stackoverflow.com/questions/tagged/sqlobject


Example
===

Create a simple class that wraps a table::

  >>> from sqlobject import *
  >>>
  >>> sqlhub.processConnection = connectionForURI('sqlite:/:memory:')
  >>>
  >>> class Person(SQLObject):
  ... fname = StringCol()
  ... mi = StringCol(length=1, default=None)
  ... lname = StringCol()
  ...
  >>> Person.createTable()

Use the object::

  >>> p = Person(fname="John", lname="Doe")
  >>> p
  
  >>> p.fname
  'John'
  >>> p.mi = 'Q'
  >>> p2 = Person.get(1)
  >>> p2
  
  >>> p is p2
  True

Queries::

  >>> p3 = Person.selectBy(lname="Doe")[0]
  >>> p3
  
  >>> pc = Person.select(Person.q.lname=="Doe").count()
  >>> pc
  1

Oleg.
-- 
Oleg Broytmanhttps://phdru.name/p...@phdru.name
   Programmers don't die, they just GOSUB without RETURN.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: stuck on time

2019-12-07 Thread RobH

On 07/12/2019 17:54, Karsten Hilbert wrote:

On Sat, Dec 07, 2019 at 05:48:00PM +, RobH wrote:

What happens if your run this line:


current_time = time.strftime("%I:%M")<<< stays at this line


in an interactive Python interpreter ?

(after you define "time" appropriately)

Karsten
--
GPG  40BE 5B0E C98E 1713 AFA6  5BC0 3BEA AC80 7D4F C89B



The python code is in a terminal window or shell, and when I run it only 
the time is displayed on an oled display, with no indication elsewhere 
of anything else. No errors of any description in the shell. It just 
appears as tho the code has stalled.


Could it be the actual font I am using which is causing the stalling.
--
https://mail.python.org/mailman/listinfo/python-list


Re: stuck on time

2019-12-07 Thread Karsten Hilbert
On Sat, Dec 07, 2019 at 06:56:17PM +, RobH wrote:

> > What happens if your run this line:
> >
> > >   current_time = time.strftime("%I:%M")<<< stays at this line
> >
> > in an interactive Python interpreter ?
> >
> > (after you define "time" appropriately)
>
> The python code is in a terminal window or shell, and when I run it only the
> time is displayed on an oled display, with no indication elsewhere of
> anything else. No errors of any description in the shell. It just appears as
> tho the code has stalled.
>
> Could it be the actual font I am using which is causing the stalling.

That does not sound likely because the line you are asserting
it is stuck on does not output anything so where should
whatever font get involved ?

So, what happens if *you* run the line in an *interactive interpreter* ?

Karsten
--
GPG  40BE 5B0E C98E 1713 AFA6  5BC0 3BEA AC80 7D4F C89B
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unicode filenames

2019-12-07 Thread DL Neil via Python-list

On 8/12/19 5:50 AM, Bob van der Poel wrote:

On Sat, Dec 7, 2019 at 4:00 AM Barry Scott  wrote:

On 6 Dec 2019, at 18:17, Bob van der Poel  wrote:

I have some files which came off the net with, I'm assuming, unicode
characters in the names. I have a very short program which takes the
filename and puts into an emacs buffer, and then lets me add information

to

that new file (it's a poor man's DB).

Next, I can look up text in the file and open the saved filename.
Everything works great until I hit those darn unicode filenames.


...


Do you get the error with python 3?

I'm running this program on Linux (Ubuntu 19.10) and Python2.


...


I've taking the coward's way out and renamed the 1/2 dozen files. Seems
that it is when I grab a filename from the DB it is in unicode and the the
textAtCursor() and then I am trying to open that file using a fork to a
pdf-display program. This is all Q&D stuff so I'm going to file it under
"mysteries of life" and live with it :)



Fair enough, for such small number no other solution could be as 
efficient! My quick-and-dirty 'solution' would only work for (very few) 
'old data files' being recognised/name-updated using Python3.



Insert here: obligatory warning about the deprecation of Python2 at the 
end of this month/year...

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Vim settings for Python (was: tab replace to space 4)

2019-12-07 Thread Bill Campbell
On Sat, Dec 07, 2019, Peter J. Holzer wrote:

>As an aside, to prevent vim from inserting tabs in the first place, set
>expandtab
>sw=4
>and maybe also
>ts=4

Inserting a comment in the file like this makes thing easy.

# vim: expandtab sw=4 ts=4 nows wm=0

Bill
-- 
INTERNET:   b...@celestial.com  Bill Campbell; Celestial Software LLC
URL: http://www2.celestial.com/ 6641 E. Mercer Way
Mobile: (206) 947-5591  PO Box 820
Fax:(206) 232-9186  Mercer Island, WA 98040-0820

Political language... is designed to make lies sound truthful and
murder respectable, and to give an appearance of solidity to pure
wind. -- George Orwell
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: stuck on time

2019-12-07 Thread RobH

On 07/12/2019 19:15, Karsten Hilbert wrote:

On Sat, Dec 07, 2019 at 06:56:17PM +, RobH wrote:


What happens if your run this line:


current_time = time.strftime("%I:%M")<<< stays at this line


in an interactive Python interpreter ?

(after you define "time" appropriately)


The python code is in a terminal window or shell, and when I run it only the
time is displayed on an oled display, with no indication elsewhere of
anything else. No errors of any description in the shell. It just appears as
tho the code has stalled.

Could it be the actual font I am using which is causing the stalling.


That does not sound likely because the line you are asserting
it is stuck on does not output anything so where should
whatever font get involved ?

So, what happens if *you* run the line in an *interactive interpreter* ?

Karsten
--
GPG  40BE 5B0E C98E 1713 AFA6  5BC0 3BEA AC80 7D4F C89B



I have tried the code in Thonny and ran it, but after about 5 minutes 
nothing happened and no errors at all.


Also just running the line in Thonny, nothing happened, no errors.

What program has or is an interactive interpreter, if it's not Thonny
--
https://mail.python.org/mailman/listinfo/python-list


Re: stuck on time

2019-12-07 Thread Karsten Hilbert
On Sat, Dec 07, 2019 at 08:38:20PM +, RobH wrote:

> I have tried the code in Thonny and ran it

Notice how I said "line", not "code".

If you hope to debug anything you need to be precise.

Karsten
--
GPG  40BE 5B0E C98E 1713 AFA6  5BC0 3BEA AC80 7D4F C89B
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unicode filenames

2019-12-07 Thread Bob van der Poel
On Sat, Dec 7, 2019 at 12:47 PM DL Neil via Python-list <
python-list@python.org> wrote:

> On 8/12/19 5:50 AM, Bob van der Poel wrote:
> > On Sat, Dec 7, 2019 at 4:00 AM Barry Scott 
> wrote:
> >>> On 6 Dec 2019, at 18:17, Bob van der Poel  wrote:
> >>>
> >>> I have some files which came off the net with, I'm assuming, unicode
> >>> characters in the names. I have a very short program which takes the
> >>> filename and puts into an emacs buffer, and then lets me add
> information
> >> to
> >>> that new file (it's a poor man's DB).
> >>>
> >>> Next, I can look up text in the file and open the saved filename.
> >>> Everything works great until I hit those darn unicode filenames.
>
> ...
>
> >> Do you get the error with python 3?
> > I'm running this program on Linux (Ubuntu 19.10) and Python2.
>
> ...
>
> > I've taking the coward's way out and renamed the 1/2 dozen files. Seems
> > that it is when I grab a filename from the DB it is in unicode and the
> the
> > textAtCursor() and then I am trying to open that file using a fork to a
> > pdf-display program. This is all Q&D stuff so I'm going to file it under
> > "mysteries of life" and live with it :)
>
>
> Fair enough, for such small number no other solution could be as
> efficient! My quick-and-dirty 'solution' would only work for (very few)
> 'old data files' being recognised/name-updated using Python3.
>
>
> Insert here: obligatory warning about the deprecation of Python2 at the
> end of this month/year...
>
>
Yeah, heard all that before :) But, seriously, I wonder how many short
(less than 100 lines) programs there are out there written in py2 that will
not run in py3. Good thing py2 will still be available to be installed for
many, many years!


-- 

 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: Unicode filenames

2019-12-07 Thread Chris Angelico
On Sun, Dec 8, 2019 at 8:33 AM Bob van der Poel  wrote:
> Yeah, heard all that before :) But, seriously, I wonder how many short
> (less than 100 lines) programs there are out there written in py2 that will
> not run in py3. Good thing py2 will still be available to be installed for
> many, many years!

If they're that short and people are depending on them, it won't be
too much work to port them. And you gain a huge measure of
reliability: you no longer have to worry about "Unicode filenames" -
or, to be more precise, "non-ASCII filenames" - because everything
will just work.

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


Re: stuck on time

2019-12-07 Thread RobH

On 07/12/2019 21:22, Karsten Hilbert wrote:

On Sat, Dec 07, 2019 at 08:38:20PM +, RobH wrote:


I have tried the code in Thonny and ran it


Notice how I said "line", not "code".

If you hope to debug anything you need to be precise.

Karsten
--
GPG  40BE 5B0E C98E 1713 AFA6  5BC0 3BEA AC80 7D4F C89B



Sorry, I should have said just the line, and it didn't return anything.
Is Thonny an interpreter then.
--
https://mail.python.org/mailman/listinfo/python-list


Re: IOError: cannot open resource

2019-12-07 Thread Python

RobH wrote:

On 07/12/2019 16:04, Peter Otten wrote:

RobH wrote:


When I run a python project with an oled display on a rasperry pi zero,
it calls for the Minecraftia.ttf font. I have the said file in
home/pi/.fonts/

I get this error:

pi@raspberrypi:~/Downloads $ python interdisplay.py
Traceback (most recent call last):
    File "interdisplay.py", line 220, in 
  display_time()
    File "interdisplay.py", line 26, in display_time
  font = ImageFont.truetype('home/pi/.fonts/Minecraftia.ttf', 35)
    File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 280,
in truetype
  return FreeTypeFont(font, size, index, encoding, layout_engine)
    File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 145,
in __init__
  layout_engine=layout_engine)
IOError: cannot open resource

PILLOW version forked from PIL 1.1.7

I have no idea to what to do about this.


You don't have the font "Minecraftia.ttf". You can either try to find and
install it or replace it with another that you already have in the
/home/pi/.fonts directory.

You may even lie about it, e. g. assuming there is a font called
"NotoSerif-Regular.ttf"

$ cd /home/pi/.fonts
$ ln NotoSerif-Regular.ttf Minecraftia.ttf

should fix the error without making changes to the code.



Thanks for that.
I actually replaced Minecraftia.ttf in the code for 
NotoSerif-Regular.ttf, after I put that font in the .font folder.

It now runs without the above errors.


You are a genious.



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


Re: stuck on time

2019-12-07 Thread Terry Reedy

On 12/7/2019 1:56 PM, RobH wrote:


    current_time = time.strftime("%I:%M")<<< stays at this line

in an interactive Python interpreter ?


In IDLE on Windows with 3.7 and 3.9, time.strftime runs fine.

>>> import time
>>> time.strftime("%I:%M")
'11:48'
>>> current_time = time.strftime("%I:%M")
>>> current_time
'11:48'

--
Terry Jan Reedy


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