[issue462628] NNTPLib supports saving BODY to a file

2022-04-10 Thread admin


Change by admin :


--
github: None -> 35193

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Saving/exporting plots from Jupyter-labs?

2022-02-21 Thread Martin Schöön
Den 2022-02-14 skrev Martin Schöön :
>
> Now I am trying out Jupyter-labs. I like it. I have two head-
> scratchers for now:
>

> 2) Why is Jupyter-labs hooking up to Google-analytics?

Now I can answer this one myself. In a tab I had been working my
way through a Holoviews tutorial. The tutorial demonstrated how
one can open the online Holoviews documentation inside a 
notebook cell. This is how google-analytics and twitter got
'involved'. Jupyter-labs was not guilty.

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


Re: Saving/exporting plots from Jupyter-labs?

2022-02-15 Thread Martin Schöön
Den 2022-02-15 skrev Reto :
> On Mon, Feb 14, 2022 at 08:54:01PM +, Martin Schöön wrote:
>> 1) In notebooks I can save a plot by right-clicking on it and do
>> save image as. In Jupyter-lab that does not work and so far I
>> have not been able to figure out how to do it. Yes, I have looked
>> in the documentation.
>
> Shift + right click brings up the usual browser menu

Thanks,

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


Re: Saving/exporting plots from Jupyter-labs?

2022-02-14 Thread Reto
On Mon, Feb 14, 2022 at 08:54:01PM +, Martin Schöön wrote:
> 1) In notebooks I can save a plot by right-clicking on it and do
> save image as. In Jupyter-lab that does not work and so far I
> have not been able to figure out how to do it. Yes, I have looked
> in the documentation.

Shift + right click brings up the usual browser menu
-- 
https://mail.python.org/mailman/listinfo/python-list


Saving/exporting plots from Jupyter-labs?

2022-02-14 Thread Martin Schöön
I have used Jupyter notebooks for some time now. I am not a heavy
or advanced user. I find the notebook format a nice way to create 
python documents.

Now I am trying out Jupyter-labs. I like it. I have two head-
scratchers for now:

1) In notebooks I can save a plot by right-clicking on it and do
save image as. In Jupyter-lab that does not work and so far I
have not been able to figure out how to do it. Yes, I have looked
in the documentation.

2) Why is Jupyter-labs hooking up to Google-analytics?

TIA,

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


[issue21140] Idle: saving Shell or an OutputWindow should default to .txt

2021-09-27 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

>From #45297, closed as duplicate.
https://discuss.python.org/t/what-is-this-syntax-i-dont-know-how-to-fix-it/10844

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Recommendation for drawing graphs and creating tables, saving as PDF

2021-06-12 Thread Chris Nyland
If you don't want to have to do any layout, Graphviz, which you mentioned,
is probably the best and there are/were Python libraries that will let you
control it to automatically produce files. The whole point of graphviz is
to do all the layout, however my only grip is it doesn't always make the
best choices and then it is a bit of a burden to get it to do what you
want. That was also years ago though so maybe the functionality has
expanded. I used it then to create huge hierarchical graphs. Additionally
Graphviz is more like a framework and there are in reality many backends to
choose from. I started to look into this to see if there were backends that
made more sense for my charts but the project lost steam and I never got
back to it.

That would be my recommendation and then like Martin said use Markdown plus
pandoc. I have been using this system for years at work and it works really
well. I will write up specifications and requirements in mark down so I can
version control them in Git then I use Markdown to convert to Word and PDF
to distribute to coworkers. If they make changes I just convert the files
back to mark down and then I can use KDiff and other merge tools to review
the changes and commit them if I want. Graphviz will export PNGs which you
can embed easily in markdown.

Graphviz can also work by typing up a simple viz file which is just text
and then that file is compiled into the visualization. That text file can
of course be version controlled which if you can't tell I am big on so this
is another bonus for me.

Chris

Chris

On Fri, Jun 11, 2021 at 10:35 PM Martin Di Paola 
wrote:

> You could try https://plantuml.com and http://ditaa.sourceforge.net/.
>
> Plantuml may not sound as the right tool but it is quite flexible and
> after a few tweak you can create a block diagram as you shown.
>
> And the good thing is that you *write* which elements and relations are
> in your diagram and it is Plantuml which will draw it for you.
>
> On the other hand, in Ditaa you have to do the layout but contrary to
> most of the GUI apps, Ditaa processes plaintext (ascii art if you want).
>
> For simple things, Ditaa is probably a good option too.
>
> Finally, I use https://pandoc.org/ to transform my markdowns into PDFs
> for a textbook that I'm writing (and in the short term for my blog).
>
> None of those are "libraries" in the sense that you can load in Python,
> however nothing should prevent you to call them from Python with
> `subprocess`.
>
> By the way, I'm interesting too in to know other tools for making
> diagrams.
>
> On Fri, Jun 11, 2021 at 08:52:20AM -0400, Neal Becker wrote:
> >Jan Erik Moström wrote:
> >
> >> I'm doing something that I've never done before and need some advise for
> >> suitable libraries.
> >>
> >> I want to
> >>
> >> a) create diagrams similar to this one
> >> https://www.dropbox.com/s/kyh7rxbcogvecs1/graph.png?dl=0 (but with more
> >> nodes) and save them as PDFs or some format that can easily be converted
> >> to PDFs
> >>
> >> b) generate documents that contains text, lists, and tables with some
> >> styling. Here my idea was to save the info as markdown and create PDFs
> >> from those files, but if there is some other tools that gives me better
> >> control over the tables I'm interested in knowing about them.
> >>
> >> I looked around around but could only find two types of libraries for a)
> >> libraries for creating histograms, bar charts, etc, b) very basic
> >> drawing tools that requires me to figure out the layout etc. I would
> >> prefer a library that would allow me to state "connect A to B", "connect
> >> C to B", "connect B to D", and the library would do the whole layout.
> >>
> >> The closest I've found it to use markdown and mermaid or graphviz but
> >> ... PDFs (perhaps I should just forget about PDFs, then it should be
> >> enough to send people to a web page)
> >>
> >> (and yes, I could obviously use LaTeX ...)
> >>
> >> = jem
> >
> >Like this?
> >https://pypi.org/project/blockdiag/
> >
> >--
> >https://mail.python.org/mailman/listinfo/python-list
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Recommendation for drawing graphs and creating tables, saving as PDF

2021-06-11 Thread Martin Di Paola

You could try https://plantuml.com and http://ditaa.sourceforge.net/.

Plantuml may not sound as the right tool but it is quite flexible and 
after a few tweak you can create a block diagram as you shown.


And the good thing is that you *write* which elements and relations are 
in your diagram and it is Plantuml which will draw it for you.


On the other hand, in Ditaa you have to do the layout but contrary to 
most of the GUI apps, Ditaa processes plaintext (ascii art if you want).


For simple things, Ditaa is probably a good option too.

Finally, I use https://pandoc.org/ to transform my markdowns into PDFs 
for a textbook that I'm writing (and in the short term for my blog).


None of those are "libraries" in the sense that you can load in Python, 
however nothing should prevent you to call them from Python with 
`subprocess`.


By the way, I'm interesting too in to know other tools for making 
diagrams.


On Fri, Jun 11, 2021 at 08:52:20AM -0400, Neal Becker wrote:

Jan Erik Moström wrote:


I'm doing something that I've never done before and need some advise for
suitable libraries.

I want to

a) create diagrams similar to this one
https://www.dropbox.com/s/kyh7rxbcogvecs1/graph.png?dl=0 (but with more
nodes) and save them as PDFs or some format that can easily be converted
to PDFs

b) generate documents that contains text, lists, and tables with some
styling. Here my idea was to save the info as markdown and create PDFs
from those files, but if there is some other tools that gives me better
control over the tables I'm interested in knowing about them.

I looked around around but could only find two types of libraries for a)
libraries for creating histograms, bar charts, etc, b) very basic
drawing tools that requires me to figure out the layout etc. I would
prefer a library that would allow me to state "connect A to B", "connect
C to B", "connect B to D", and the library would do the whole layout.

The closest I've found it to use markdown and mermaid or graphviz but
... PDFs (perhaps I should just forget about PDFs, then it should be
enough to send people to a web page)

(and yes, I could obviously use LaTeX ...)

= jem


Like this?
https://pypi.org/project/blockdiag/

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

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


Re: Recommendation for drawing graphs and creating tables, saving as PDF

2021-06-11 Thread Neal Becker
Jan Erik Moström wrote:

> I'm doing something that I've never done before and need some advise for
> suitable libraries.
> 
> I want to
> 
> a) create diagrams similar to this one
> https://www.dropbox.com/s/kyh7rxbcogvecs1/graph.png?dl=0 (but with more
> nodes) and save them as PDFs or some format that can easily be converted
> to PDFs
> 
> b) generate documents that contains text, lists, and tables with some
> styling. Here my idea was to save the info as markdown and create PDFs
> from those files, but if there is some other tools that gives me better
> control over the tables I'm interested in knowing about them.
> 
> I looked around around but could only find two types of libraries for a)
> libraries for creating histograms, bar charts, etc, b) very basic
> drawing tools that requires me to figure out the layout etc. I would
> prefer a library that would allow me to state "connect A to B", "connect
> C to B", "connect B to D", and the library would do the whole layout.
> 
> The closest I've found it to use markdown and mermaid or graphviz but
> ... PDFs (perhaps I should just forget about PDFs, then it should be
> enough to send people to a web page)
> 
> (and yes, I could obviously use LaTeX ...)
> 
> = jem

Like this?
https://pypi.org/project/blockdiag/

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


Re: Recommendation for drawing graphs and creating tables, saving as PDF

2021-06-11 Thread Rich Shepard

On Fri, 11 Jun 2021, Jan Erik Moström wrote:


I looked around around but could only find two types of libraries for a)
libraries for creating histograms, bar charts, etc, b) very basic drawing
tools that requires me to figure out the layout etc. I would prefer a
library that would allow me to state "connect A to B", "connect C to B",
"connect B to D", and the library would do the whole layout.


JEM,

PSTricks 


(and yes, I could obviously use LaTeX ...)


They work well together.

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


Recommendation for drawing graphs and creating tables, saving as PDF

2021-06-11 Thread Jan Erik Moström
I'm doing something that I've never done before and need some advise for 
suitable libraries.


I want to

a) create diagrams similar to this one 
https://www.dropbox.com/s/kyh7rxbcogvecs1/graph.png?dl=0 (but with more 
nodes) and save them as PDFs or some format that can easily be converted 
to PDFs


b) generate documents that contains text, lists, and tables with some 
styling. Here my idea was to save the info as markdown and create PDFs 
from those files, but if there is some other tools that gives me better 
control over the tables I'm interested in knowing about them.


I looked around around but could only find two types of libraries for a) 
libraries for creating histograms, bar charts, etc, b) very basic 
drawing tools that requires me to figure out the layout etc. I would 
prefer a library that would allow me to state "connect A to B", "connect 
C to B", "connect B to D", and the library would do the whole layout.


The closest I've found it to use markdown and mermaid or graphviz but 
... PDFs (perhaps I should just forget about PDFs, then it should be 
enough to send people to a web page)


(and yes, I could obviously use LaTeX ...)

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


[issue43457] Include simple file loading and saving functions in JSON standard library.

2021-03-09 Thread Inada Naoki


Inada Naoki  added the comment:

I created a new vote for naming.
https://discuss.python.org/t/vote-new-function-for-reading-json-from-path/7603

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43457] Include simple file loading and saving functions in JSON standard library.

2021-03-09 Thread Inada Naoki


Inada Naoki  added the comment:

This idea is discussed several times. Last discussion thread is:
https://mail.python.org/archives/list/python-id...@python.org/thread/YHO575YY4FQC3GBDF4SKOWIEAUSY3OQX/#YHO575YY4FQC3GBDF4SKOWIEAUSY3OQX

--
nosy: +methane

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43457] Include simple file loading and saving functions in JSON standard library.

2021-03-09 Thread nervecenter


New submission from nervecenter :

Python has a "batteries included" approach to standard library construction. To 
that end, commonly used procedures are often included as functions; adding 
sugar to the language is often exchanged for adding sugar to libraries.

One of these common procedures in small-scale scripting tasks is loading a JSON 
file as simple data structures and saving simple data structures as a JSON 
file. This is normally handled using context managers, json.load(), and 
json.dump(). This is a bit cluttered and, I'd argue, not quite as Pythonic as 
the philosophy demands. I have a small file containing this code:

import json

def load_file(filename, *args, **kwargs):
with open(filename, "r") as fp:
data = json.load(fp, *args, **kwargs)
return data

def save_file(data, filename, *args, **kwargs):
with open(filename, "w") as fp:
json.dump(data, fp, *args, **kwargs)

I'd say, toss these two functions into the json module. Those two functions 
contain the clutter. For all other users, loading and saving JSON files become 
one-line function calls. This is convenient and batteries-included.

--
components: Library (Lib)
messages: 388403
nosy: nervecenter
priority: normal
severity: normal
status: open
title: Include simple file loading and saving functions in JSON standard 
library.
type: enhancement

___
Python tracker 
<https://bugs.python.org/issue43457>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Dataframe to postgresql - Saving the dataframe to memory using StringIO

2020-10-22 Thread Chris Angelico
On Fri, Oct 23, 2020 at 3:35 AM Grant Edwards  wrote:
> Moving from 2.x to 3.x isn't too bad, but trying to maintain
> compatiblity with both is painful. At this point, I would probably
> just abandon 2.x.
>

Definitely. No point trying to support both when you're starting with
code from a Py3 example.

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


Re: Dataframe to postgresql - Saving the dataframe to memory using StringIO

2020-10-22 Thread Grant Edwards
On 2020-10-22, Chris Angelico  wrote:
> On Fri, Oct 23, 2020 at 12:15 AM Shaozhong SHI  wrote:

>> What should I know or watch out if I decide to move from Python 2.7
>> to Python 3?
>
> Key issues? Well, for starters, you don't have to worry about whether
> your strings are Unicode or not. They just are, unless you explicitly
> need them to be bytes.

The 'bytes' thing is important. If you use serial ports, sockets, or
anything else that's raw bytes, that code will need to be examined
carefully.

The usage of the 'bytes' type in 3.x isn't at all like 2.x:

Python2:
>>> bytes('abcd')
'abcd'
>>> bytes(3)
'3'
>>> bytes([0,1,2])
'[0, 1, 2]'

Python3:
>>> bytes('abcd')
Traceback (most recent call last):
  File "", line 1, in 
TypeError: string argument without an encoding
>>> bytes(3)
b'\x00\x00\x00'
>>> bytes([0,1,2])
b'\x00\x01\x02

Python2:
>>> b'abcd'[2]
'c'

Python3:
>>> b'abcd'[2]
99

Moving from 2.x to 3.x isn't too bad, but trying to maintain
compatiblity with both is painful. At this point, I would probably
just abandon 2.x.

--
Grant



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


Re: Dataframe to postgresql - Saving the dataframe to memory using StringIO

2020-10-22 Thread Chris Angelico
On Fri, Oct 23, 2020 at 12:15 AM Shaozhong SHI  wrote:
>
> Thanks, Chris.
>
> What should I know or watch out if I decide to move from Python 2.7 to Python 
> 3?
>
> What are the key issues?  Syntax?
>

Keep it on-list please :)

Key issues? Well, for starters, you don't have to worry about whether
your strings are Unicode or not. They just are, unless you explicitly
need them to be bytes. Syntax is probably going to be fine, since
you're taking examples that were written for Python 3 anyway. There's
a LOT more features in Python 3, since it's had another decade of
development than Python 2 has had.

Give it a try.

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


Re: Dataframe to postgresql - Saving the dataframe to memory using StringIO

2020-10-22 Thread Marco Sulla
Never worked with ZFS, it sounds interesting. Anyway, IMHO it's much more
simple to save to disk also for debugging: you have not to extract the data
from the db if you need to inspect them.

On Thu, 22 Oct 2020 at 14:39, D'Arcy Cain  wrote:

> On 10/22/20 7:23 AM, Marco Sulla wrote:
> > I would add that usually I do not recommend saving files on databases. I
> > usually save the file on the disk and the path and mime on a dedicated
> > table.
>
> I used to do that because backing up the database became huge.  Now I use
> ZFS snapshots with send/receive so the backup only copies the changed
> blocks
> so I keep it in the database.  That way the data is available from any
> client with database access without the need to give access to the server.
>
> PostgreSQL can handle it.
>
> --
> D'Arcy J.M. Cain
> Vybe Networks Inc.
> A unit of Excelsior Solutions Corporation - Propelling Business Forward
> http://www.VybeNetworks.com/
> IM:da...@vybenetworks.com VoIP: sip:da...@vybenetworks.com
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Dataframe to postgresql - Saving the dataframe to memory using StringIO

2020-10-22 Thread D'Arcy Cain

On 10/22/20 7:23 AM, Marco Sulla wrote:

I would add that usually I do not recommend saving files on databases. I
usually save the file on the disk and the path and mime on a dedicated
table.


I used to do that because backing up the database became huge.  Now I use 
ZFS snapshots with send/receive so the backup only copies the changed blocks 
so I keep it in the database.  That way the data is available from any 
client with database access without the need to give access to the server.


PostgreSQL can handle it.

--
D'Arcy J.M. Cain
Vybe Networks Inc.
A unit of Excelsior Solutions Corporation - Propelling Business Forward
http://www.VybeNetworks.com/
IM:da...@vybenetworks.com VoIP: sip:da...@vybenetworks.com


OpenPGP_signature
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Dataframe to postgresql - Saving the dataframe to memory using StringIO

2020-10-22 Thread Chris Angelico
On Thu, Oct 22, 2020 at 8:28 PM Shaozhong SHI  wrote:
>
> I found this last option is very interesting.
>
> Saving the dataframe to memory using StringIO
>
> https://naysan.ca/2020/06/21/pandas-to-postgresql-using-psycopg2-copy_from/
>
> But, testing shows
> unicode argument expected, got 'str'
>
> Any working example for getting DataFrame into a PostgreSQL table directly?
>

That error suggests that you're using a legacy version of Python. The
page you're linking to has been written on the assumption that you're
using Python 3.

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


Re: Dataframe to postgresql - Saving the dataframe to memory using StringIO

2020-10-22 Thread Marco Sulla
I would add that usually I do not recommend saving files on databases. I
usually save the file on the disk and the path and mime on a dedicated
table.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Dataframe to postgresql - Saving the dataframe to memory using StringIO

2020-10-22 Thread Marco Sulla
Try to save it in a binary field on PG using hdf5:

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_hdf.html

On Thu, 22 Oct 2020 at 11:29, Shaozhong SHI  wrote:

> I found this last option is very interesting.
>
> Saving the dataframe to memory using StringIO
>
> https://naysan.ca/2020/06/21/pandas-to-postgresql-using-psycopg2-copy_from/
>
> But, testing shows
> unicode argument expected, got 'str'
>
> Any working example for getting DataFrame into a PostgreSQL table directly?
>
> Regards,
>
> David
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Dataframe to postgresql - Saving the dataframe to memory using StringIO

2020-10-22 Thread Shaozhong SHI
I found this last option is very interesting.

Saving the dataframe to memory using StringIO

https://naysan.ca/2020/06/21/pandas-to-postgresql-using-psycopg2-copy_from/

But, testing shows
unicode argument expected, got 'str'

Any working example for getting DataFrame into a PostgreSQL table directly?

Regards,

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


Re: Problem saving datetime to file and reading it back for a calculation

2020-10-11 Thread Cameron Simpson
On 11Oct2020 20:39, Steve  wrote:
>Still, I enjoyed the kluge I created making it work based on discovery...

Poking around in the datetime module will definitely make you aware of
its power, and its pitfalls. Well worth doing. At the very least you'll
usually want it when printing times out for humans.

But seconds is generally simpler and reliable, particularly as it tosses
timezones straight out the window - it is all just arithmetic.

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


RE: Problem saving datetime to file and reading it back for a calculation

2020-10-11 Thread Steve
Thanks for the responses.  Somehow, all of my python messages were shifted
into the deleted folder so I missed all of them until I caught the one from
MRAB.

I will sift through them and probably update my technique to use seconds as
suggested.

Still, I enjoyed the kluge I created making it work based on discovery...



Footnote:
If 666 is evil then
25.8 is the square root of all evil.


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


Re: Problem saving datetime to file and reading it back for a calculation

2020-10-11 Thread MRAB

On 2020-10-11 20:25, Steve wrote:

Thanks for the response.

I must have spent hours looking on-line for a method to treat datetime
variables yet not one site mentioned the "pickle" module you indicatged.  I
did, however solve my problem.  It may be a kluge but it seems to work.

I learned that I cannot use print() to display the value of datetime but
once I saved it to a file, I could see it.  If I used "d3 = d2.isoformat" it
could be sent to a file with a write statement.  Apparently, it gives a
write/read format and places a T between the date and time as a separator.

In trying to read it back into the program and work the calculation, I had
to replace the T with a space and some formatting. It all worked.


[snip]

Given:

 import datetime

To convert a datetime d to an ISO-format string, you can use:
s = d.isoformat()

To convert an ISO-format string s to a datetime, you can use:

d = datetime.datetime.fromisoformat()
--
https://mail.python.org/mailman/listinfo/python-list


RE: Problem saving datetime to file and reading it back for a calculation

2020-10-11 Thread Steve
Thanks for the response.

I must have spent hours looking on-line for a method to treat datetime
variables yet not one site mentioned the "pickle" module you indicatged.  I
did, however solve my problem.  It may be a kluge but it seems to work.

I learned that I cannot use print() to display the value of datetime but
once I saved it to a file, I could see it.  If I used "d3 = d2.isoformat" it
could be sent to a file with a write statement.  Apparently, it gives a
write/read format and places a T between the date and time as a separator. 

In trying to read it back into the program and work the calculation, I had
to replace the T with a space and some formatting. It all worked.
#===

LBD = "LBD"
d2 =  datetime.now()
d2i = d2.isoformat()

with open("TimeDate.txt", 'r') as infile:
 for BottleInfo in infile: # loop to find each line in the file for that
dose
   BottleInfo = BottleInfo.strip()

   if ((BottleInfo[0:3]== "LBD")):
BottleData = BottleInfo[0:43].strip()

BottleDataA = BottleData[4:14].strip()
BottleDataB = BottleData[16:30].strip()
BottleDataC = BottleDataA + " " + BottleDataB
print("BottleDataC = <" + BottleDataC + ">")
# I guess I could have searched for the "T" and replaced it.
print()
d1 = BottleDataC

import datetime
dto = datetime.datetime.strptime(d1, '%Y-%m-%d %H:%M:%S.%f')
dti = dto.isoformat()

HoursDiff = int((d2-dto).total_seconds()/3600)
print("HoursDiff = " + str(HoursDiff))
print()

TimeDateInfo=open("TimeDate.txt", "a") 
TimeDateInfo.write("{0:>5} {1:>25} {2:>5}\n".format (LBD, d2i, HoursDiff))
TimeDateInfo.close()

# ===

Granted, there may be other ways to do this but I actually enjoy the
exploration...
Still, I would like to see other methods.
Steve

-Original Message-
From: Dieter Maurer  
Sent: Sunday, October 11, 2020 12:48 PM
To: Steve 
Subject: Re: Problem saving datetime to file and reading it back for a
calculation

Steve wrote at 2020-10-10 18:17 -0400:
>I would like to use the line:
>HoursDiff = int((d2-d1).total_seconds()/3600) to determine the 
>difference in hours between two timedate entries.
>
>The variable d2 is from datetime.now()
>and d1 is read from a text file.
>
>I can save d2 to the file only if I convert it to string and, at a later
>date, it gets read back in as d1 as string.   The variable d1 as string
will
>not work in the HoursDiff statement.

Python's "pickle" module provides support for storing (most) objects to
files and read them back.

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


Re: Problem saving datetime to file and reading it back for a calculation

2020-10-10 Thread Chris Angelico
On Sun, Oct 11, 2020 at 12:57 PM Cameron Simpson  wrote:
> Personally I strongly dislike using datetimes for computation or as the
> basis for time record keeping, essentially because of the timezone issue
> but also because the human calendar is a complex disaster of illfitting
> units (days in a year? variable; days in a month? variable; that table
> of days per unit? variable depending on your time in history).
>
> Instead, I always try to work in POSIX timestamps, an absolute number of
> seconds since midnight, 1 January 1970 GMT. You can always do arithmetic
> directly between these in seconds, then convert for presentation
> purposes whenever.
>

Absolutely agree, with the annoying exception of recurring events. If
a human says "this happens every Monday at 2pm", then the human
expects it to recur every Monday at 2pm, not every 604800 seconds. The
difference shows up when the conversion between UTC and local time
changes - most commonly when Daylight Saving Time starts or ends...

(And I guess if you care about leap seconds, then Unix time would be
inappropriate there too. But I rather doubt that most of us are
bothered by that.)

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


Re: Problem saving datetime to file and reading it back for a calculation

2020-10-10 Thread Cameron Simpson
On 10Oct2020 18:17, Steve  wrote:
>I would like to use the line:
>HoursDiff = int((d2-d1).total_seconds()/3600)
>to determine the difference in hours between two timedate entries.
>
>The variable d2 is from datetime.now()
>and d1 is read from a text file.
>
>I can save d2 to the file only if I convert it to string and, at a later
>date, it gets read back in as d1 as string.

That is the nature of text files.

>The variable d1 as string will
>not work in the HoursDiff statement.

Because it is a string.

Peter has described a way to transcribe a datetime in an arbitrary string 
format and back. Note that his example formats are "naive" - they don't know 
what you timezone is, and you want that if that ever varies (not just 
datetimes in contexts from different places, but also at different times of 
the year if you run different summer and winter times, particularly 
troublesome around the transition from one to the other).

>To me, it looks like a problem in formatting.
>How do I fix this?

Personally I strongly dislike using datetimes for computation or as the 
basis for time record keeping, essentially because of the timezone issue 
but also because the human calendar is a complex disaster of illfitting 
units (days in a year? variable; days in a month? variable; that table 
of days per unit? variable depending on your time in history).

Instead, I always try to work in POSIX timestamps, an absolute number of 
seconds since midnight, 1 January 1970 GMT. You can always do arithmetic 
directly between these in seconds, then convert for presentation 
purposes whenever.

Because you're now working in seconds directly, you go:

HoursDiff = int((t2-t1)/3600)

or:

HoursDiff = (t2-t1) // 3600

When you first collect your datetime, convert it to a POSIX timestamp 
immediately. If you're _starting_ from datetime.now(), do not do that! Just 
start with time.time() and no conversion is needed at all.

Just _present_ in datetime formats if you need to. DO NOT try to work 
with them as your basic type - they are a source of pitfalls.

As far as storing timestamps in a file, they're ints or floats; just 
write them out.

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


Re: Problem saving datetime to file and reading it back for a calculation

2020-10-10 Thread Peter Pearson
On Sat, 10 Oct 2020 18:17:26 -0400, Steve  wrote:
> I would like to use the line:
> HoursDiff = int((d2-d1).total_seconds()/3600)
> to determine the difference in hours between two timedate entries.
>
> The variable d2 is from datetime.now()
> and d1 is read from a text file.
>
> I can save d2 to the file only if I convert it to string and, at a later
> date, it gets read back in as d1 as string.   The variable d1 as string will
> not work in the HoursDiff statement.
>
> To me, it looks like a problem in formatting.
> How do I fix this?

datetime.datetime.strftime and datetime.datetime.strptime ?

>>> t = datetime.datetime.now()
>>> t.strftime("%Y-%m-%d %H:%M:%S")
'2020-10-10 18:02:33'
>>> b = datetime.datetime.strptime("2020-09-09 12:34:56", "%Y-%m-%d %H:%M:%S")
>>> b.strftime("%Y-%m-%d %H:%M:%S")
'2020-09-09 12:34:56'
>>> 

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


Problem saving datetime to file and reading it back for a calculation

2020-10-10 Thread Steve
I would like to use the line:
HoursDiff = int((d2-d1).total_seconds()/3600)
to determine the difference in hours between two timedate entries.

The variable d2 is from datetime.now()
and d1 is read from a text file.

I can save d2 to the file only if I convert it to string and, at a later
date, it gets read back in as d1 as string.   The variable d1 as string will
not work in the HoursDiff statement.

To me, it looks like a problem in formatting.
How do I fix this?

Steve


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


[issue40553] Python 3.8.2 Mac freezing/not responding when saving new programs

2020-08-27 Thread Alexander Boeckmann


Alexander Boeckmann  added the comment:

So over the past week the issue resolved its self. I unfortunately did not get 
a video or a screenshot but thought you might want to know this
So maybe Apple did something or you guys fixed it. Anyways, have a good day!

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40553] Python 3.8.2 Mac freezing/not responding when saving new programs

2020-08-20 Thread Ned Deily


Ned Deily  added the comment:

> Would taking a video help?

It couldn't hurt and might very well help.

> I'll make one anyways

Thank you!

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40553] Python 3.8.2 Mac freezing/not responding when saving new programs

2020-08-19 Thread Alexander Boeckmann


Alexander Boeckmann  added the comment:

Hey! I have the exact same thing as described happening! Python freezes when I 
try to save new files which sucks. 
I'm on Catalina: 10.15.6
IDLE: 3.8.5
Brand new MacBook Air
As said earlier the only way out is to force quit. Would taking a video help?
I'll make one anyways

--
nosy: +aboeckmann

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40553] Python 3.8.2 Mac freezing/not responding when saving new programs

2020-08-14 Thread Ned Deily


Ned Deily  added the comment:

James, thanks very much for your detailed instructions. Alas, once again, I am 
unable to reproduce the hanging behavior under apparently similar conditions 
(10.5.6, Documents folder on iCloud, etc). I know this is frustrating to all of 
us. I have one new concrete suggestion: if someone who can reproduce this 
behavior at will is willing to allow me to screen share into their system (via 
Apple's Messages app) so they can demonstrate it live, perhaps that will allow 
us to better isolate the problem.  If anyone is interested in helping with 
this, contact me via email (nad at python dot org) and we can set up a time.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40553] Python 3.8.2 Mac freezing/not responding when saving new programs

2020-08-10 Thread James Franks


James Franks  added the comment:

Hope this helps:

I'm running Python Shell 3.8.5 on MacOSx 10.15.6 (Catalina).  I can reproduce 
this hang easily.

Open any existing module or create a new one.  Can save the existing module or 
a new one just fine under the same name. (File menu - Save)

Using "Save as..." from File dropdown menu, Windows appears, change the name, 
hit Save button and IDLE hangs.

After approximately a minute the window becomes active again, but when hitting 
any button (Cancel or Save) it hangs again.  No way to get out of this but 
force quit IDLE.

My files are in iCloud documents folder.

Did the same test with a Mac running Mojave (10.14.6) Also with Python Shell 
3.8.5.  Works fine.  Seems to be something with Catalina as some have 
mentioned. 

Please help.  This is extremely frustrating for someone like me just trying to 
learn Python.  I will switch over to the machine running Mojave.  Thanks for 
helping!

--
nosy: +franksj

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41329] IDLE not saving .py files

2020-07-17 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

In calling this a duplicate, and suggesting the fix above, I am assuming that 
a) you are using the new 3.8.4 and b) you have a non-ascii character in the .py 
file or files you tested.  Since several years ago, the is the only case of 
save failing that I know of.  If either is not the case, please reopen and 
report exact os, python version, minimal file that does not save, and any other 
possibly relevant details you can think of.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41329] IDLE not saving .py files

2020-07-17 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

Add 'import io' to the top of /Lib/idlelib/iomenu.py.

--
resolution:  -> duplicate
stage:  -> resolved
status: open -> closed
superseder:  -> IDLE: add missing import io in iomenu.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41329] IDLE not saving .py files

2020-07-17 Thread Nick.Lupariello


New submission from Nick.Lupariello :

IDLE will not save .py files. Neither Ctrl + S nor file -> Save file nor file 
-> Save file as function as intended and the .py file is not updated. 
This happens for both 32 bit and 64 bit distributions on multiple computers 
with 4 GB of ram running on a AMD A6-9220e RADEON R4. Tested installation in 
multiple locations. 
IDLE will not write to file anywhere in the file system including documents, 
desktop, and the installation folder itself.

--
assignee: terry.reedy
components: IDLE
messages: 373854
nosy: nicklupe13, terry.reedy
priority: normal
severity: normal
status: open
title: IDLE not saving .py files
type: behavior
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue41329>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21140] Idle: saving Shell or an OutputWindow should default to .txt

2020-06-06 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

There was a recent stackoverflow question in which newbie pulled shell log into 
editor and ran as is.  Got SyntaxError as 'Python 3' start of startup message.

--
versions: +Python 3.10 -Python 3.6, Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27965] Automatic .py extension when saving with IDLE on OSX

2020-06-06 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
resolution:  -> duplicate
stage:  -> resolved
status: open -> closed
superseder:  -> IDLE does not supply a default ext of .py on Windows or OS X 
for new file saves

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40553] Python 3.8.2 Mac freezing/not responding when saving new programs

2020-05-11 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

By 'preview', I meant the listing of existing file in the directory, such as 
Documents.  IDLE displays this but, as I inferred and you and Bev confirmed, 
this is not standard on macOS, as there is a button (which I did not noticed 
before) to show or hide the file list and other stuff. (There is no such button 
on Windows.) So *if* it is the problem culprit for some people, we could, I 
presume, leave the pane initially hidden.

Is the filelist pane a 'sheet'?  Could the recent 'sheets' fix (Christian's 
comment) for these dialogs on Catalina be involved?  What is your latest take 
on 8.6.10 for OSX?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40553] Python 3.8.2 Mac freezing/not responding when saving new programs

2020-05-11 Thread Ned Deily


Ned Deily  added the comment:

>To debug, and test Raymond's hypothesis, someone please try this minimal 
>(IDLE-free) code to show the dialog and print the return.  
>This does not display a preview, even after selecting a location, such as 
>Documents, on the 3rd line.

Terry, I'm not sure I know what you mean here by preview. Do you mean the 
Column view of the Save sheet?  As "Bev in TX" explained in the quote you 
supplied earlier, the standard macOS Save or Save As save sheet which nearly 
all macOS apps use including Tk in IDLE has several settings, settings that are 
usually remembered across application invocations. By default initially, a 
compact display is given with boxes for Save As, Tags, and a pull-down Where 
list of folders.  To its right, there should be an button with a "V" icon.  
When pressed, the "V" changes to a "^" and the Save sheet expands to show more 
stuff.  What stuff it shows depends on the setting of the view options which 
can be accessed by clicking on the button with an array of six little squares 
on it, usually towards the upper left side of the Save sheet.  In it are the 
three main Show Items as options: "Icons", "List", "Columns". There are other 
options in there, too. So when discussing the appearance of macOS Open or Sa
 ve dialog sheets, one has to be really precise about what options are in 
effect for that particular Save. Those are under the control of the user and, 
again, are remembered by the operating system. Note also that for Save using he 
column view, the system does not show previews of existing files; it does for 
Open files, which you should be able to see if you substitute tk_getOpenFile in 
your test code.

In any case, I ran your test on both 10.15 and 10.14 and so far have still seen 
no problems, no hanging. I don't doubt these reports that people are seeing 
hangs but we still need to be able to reproduce them.  

FWIW, for every macOS Python installer before it is permitted to be released, I 
run a smoke test that, among other things, does essentially does what is 
reported here: launch IDLE.app, open a new file window, add a few lines 
including a print function, preess F5 to Run bringing up the Save dialog, Save 
the file, and verify that the expected output shows up in the IDLE shell 
window. Each installer is tested on at least one macOS system level, always the 
latest release and usually at least one older release. In years of doing this, 
I've never seen a hang like those being reported. So that's why I'm 
particularly curious about this because there is a lot of baseline experience 
over many releases of macOS, Python, and Tk for that matter. We'll keep 
searching.  But it would still be *really* helpful if, as I requested before, 
someone who does see these hangs and can reliably reproduce them, documents 
*exactly* all the steps to do so, from exactly how IDLE is launches to exactly 
how the Sav
 e dialog is invoked (by menu bar or keyboard shortcut or ...) and what options 
of the Save dialog are in effect.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40553] Python 3.8.2 Mac freezing/not responding when saving new programs

2020-05-11 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

Raymond, can you run the tests I suggested above?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40553] Python 3.8.2 Mac freezing/not responding when saving new programs

2020-05-11 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

Mat Wichmann responded
"we had three of these in the last few weeks sent to
webmas...@python.org.  I just went back and pinged those folks with a
request to look in on the issue, and contribute to it if they had
anything new/useful to add."

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40553] Python 3.8.2 Mac freezing/not responding when saving new programs

2020-05-09 Thread Terry J. Reedy

Terry J. Reedy  added the comment:

I asked about other people's experiences on python-list and got 2 responses so 
far.
---

On macOS The default Save/Save as dialogs are short, only displaying a few 
major folders along with Favorites and Recents.  That dialog doesn’t display 
folder contents.  However, you can get an expanded dialog by clicking on the 
little arrow to the right of the Where box.  Using that dialog allows one to 
select any folder and displays folder contents.  

I tried using both Save and Save as, and was unable to duplicate the problem 
with either the short or the long dialog.

Python 3.8.2
macOS Catalina 10.15.4
Bev in TX
---

Fairly recently, Tk has got many bugfixes because of changes in OSX. Here is 
the file that implements the file dialogs:
  https://core.tcl-lang.org/tk/artifact/d72cdfbcbfaa717f
and the history:
  
https://core.tcl-lang.org/tk/finfo?name=macosx/tkMacOSXDialog.c=d72cdfbcbfaa717f

As you can see, it has been touched two days ago (!) to restore some window 
behaviour, which was switched of because of Catalina last August (this commit)
https://core.tcl-lang.org/tk/info/59b1d265c2444112


Christian Gollwitzer
---

Ned, what is your latest experience with 8.6.10?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40553] Python 3.8.2 Mac freezing/not responding when saving new programs

2020-05-08 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

What is acting up here is the Catalina system SaveAs dialog on some systems 
with some settings when closing after being asked to display the current 
contents of the target location, allow the content to be variously filtered or 
not, and add a default extension.  (I use all of these features.)  I looked at 
3 Apple apps, Safari, Maps, and they omit the content display, and hence 
filtering. It it is only the display that is bugged, they would not show the  
problem.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40553] Python 3.8.2 Mac freezing/not responding when saving new programs

2020-05-08 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

When I click Full Disk Access in Mohave, I see an empty box with a Header 
something like "All app to access Mail, ..., and all user data".  None of it 
has anything obviously to do with the user Documents folder.  Nor does it seem 
appropriate for a non-top-admin user on a multiuser machine.  Below the box are 
[+][-] buttons.  [+] opens the standard open dialog to select an app to add.  
There is nothing like 
  [ ] Add Python and IDLE

Ned, is Catalina known to have tightened up some security settings?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40553] Python 3.8.2 Mac freezing/not responding when saving new programs

2020-05-08 Thread Zain Said


Zain Said  added the comment:

Ned, I do not use DropBox nor do i have Desktop & Documents Folders checked 
under my iCloud settings. 

Someone else in the community reached out to me and suggested that if IDLE is 
acting up its not worth the hassle. And that they're alternatives. I came a 
across an editor called Atom. Seems interesting. Might give it a try.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40553] Python 3.8.2 Mac freezing/not responding when saving new programs

2020-05-08 Thread Ned Deily


Ned Deily  added the comment:

That enabling FullDiskAccess makes a difference makes some sense but that is 
not something we should be recommending without better understanding what's 
going on here. We still need a reproducible test case; I still am not able to 
reproduce. Raymond, your hint about Dropbox is promising; can you say more, 
i.e. do you see hangs if you the folder you are saving to is within your 
Dropbox folder hierarchy? Zain, do you use Dropbox?  And do either of you have 
your Documents folder stored in iCloud:

System Preferences -> Apple ID (top right) -> iCloud -> iCloud Drive (Options) 
-> Documents -> Desktop & Documents Folders (checked)

--

___
Python tracker 
<https://bugs.python.org/issue40553>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40553] Python 3.8.2 Mac freezing/not responding when saving new programs

2020-05-08 Thread Zain Said


Zain Said  added the comment:

I posted my issue on Experts Exchange and they suggested to go to system 
preferences>Security>go to privacy tab on the top>scroll down to Full 
Disk Access>Add IDLE and Python>then check off the box next to it> 

Since then my issue with IDLE not being able to save (save as) new programs has 
gone away. 

Maybe try this and let me know if this solves you're issue. 

Also I'm fairly new to python and coding in general and i rarely use terminal.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40553] Python 3.8.2 Mac freezing/not responding when saving new programs

2020-05-08 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Zain, do you happen to be working in a Dropbox synced directory when you 
observe the failure?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40553] Python 3.8.2 Mac freezing/not responding when saving new programs

2020-05-07 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

Zain, what I understand is:
> python3.8 -m idlelib # To open idle from Terminal
In IDLE, File=>New, then File=>SaveAs
In dialog opened to Documents, enter name in Save As box, then click Save.

For me 2012? Macbook Air with 10.14.6? Mohave and 3.8.3rc1, dialog disappears 
and the (blank) file is saved, with a confirmation dialog if name exits.

For you, the Documents name list disappears and maybe something else (or vice 
versa) and the dialog freezes.  I presume keys and clicks have no effect.  The 
freezing itself is almost certainly an issue between macOS and tcl/tk 8.6.8.  
If you start IDLE in Terminal, does anything error message appear?

The relevant IDLE code is idlelib.iomenu.IOBInding.asksavefile, which creates 
an instance of tkinter.filedialog.SaveAs and calls its show method, inherited 
from tkinter.commondialog.CommonDialog.  The important line there is 's = 
w.tk.call(self.command, )', where the save as command is 
'tk_getSaveFile'.  This tk command is documented in
https://www.tcl.tk/man/tcl8.6/TkCmd/getOpenFile.htm.  
There are Mac-specific items but nothing jumped out at me as significant for 
this issue.

To debug, and test Raymond's hypothesis, someone please try this minimal 
(IDLE-free) code to show the dialog and print the return.  (Interactive should 
work, at least on IDLE.)

import tkinter as tk
r = tk.Tk()
print(r.tk.call('tk_getSaveFile'))

This does not display a preview, even after selecting a location, such as 
Documents, on the 3rd line.  If that works, try deleting the 'dir' option in 
the .show call.  Other options in the SaveAs and show calls could be 
experimentally deleted if needed.  If something works, we could use 
platform.mac_ver()[0].split('.')[1] to detect Catalina and switch to the 
workaround.

--
versions: +Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40553] Python 3.8.2 Mac freezing/not responding when saving new programs

2020-05-07 Thread Zain Said


Zain Said  added the comment:

The screenshot link is at the top of the thread

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40553] Python 3.8.2 Mac freezing/not responding when saving new programs

2020-05-07 Thread Zain Said


Zain Said  added the comment:

Sure i'll supply a screenshot 
This problem doesn't effect saving in general after editing existing programs 
by the way.
My process of saving a program:
  - I'll open IDLE (Python 3.8.2)
  - write anything at all
  - I'll either hit command>s or click file>save as then ill be prompted to 
name my program and then save as (also if i want to rename an existing program 
the same issue occurs)
  - after typing in the name of the new program ill click save as then most of 
the window goes blank (you'll see in the screenshot)

--
Added file: https://bugs.python.org/file49139/Screen Shot 2020-05-07 at 3.46.02 
PM.png

___
Python tracker 
<https://bugs.python.org/issue40553>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40553] Python 3.8.2 Mac freezing/not responding when saving new programs

2020-05-07 Thread Ned Deily


Ned Deily  added the comment:

Zain and/or Raymond: can you please give the exact steps to reproduce this 
problem, including exactly how you invoke IDLE, the Python version info and 
build date info from the IDLE shell window, the details of exactly how you 
invoke Save As (i.e whether via clicking on the menu bar File menu or instead 
by using a keyboard shortcut like shift-cmd-S. And when the SaveAs window 
appears perhaps a screen shot or at least what options you have selected 
(icons, list, etc, expanded or compressed window) and what is the default 
folder it opens to. I am not able to reproduce a hang although I do see some 
delays. Also what happens if you just use Save for a new file rather than Save 
As? If it's a new file, that should also produce a Save file window and that's 
what I always use when smoke testing.  EIther should work, of course :(

--
nosy: +ned.deily

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40553] Python 3.8.2 Mac freezing/not responding when saving new programs

2020-05-07 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Perhaps we could create an option in the general settings that offers a 
workaround:  open a regular text window to get the filename.  

This wouldn't be as pretty (won't display filenames, offer mouse support, won't 
show file previews), but it would be reliable.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40553] Python 3.8.2 Mac freezing/not responding when saving new programs

2020-05-07 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

I frequently have this issue as well.  My workaround is awful:  I go to the 
terminal prompt to create an empty file with the desired name, and then open it 
up in IDLE to edit and save.  This avoids the SaveAs dialog window that 
triggers the failure.

This doesn't happen to me with new, empty directories.  So, my best guess is 
that the document preview in the SaveAs window is triggering the failure.  

This problem may go away in the future with a O/S update or with a Tcl/Tk 
update. AFAICT, IDLE doesn't have any way to ask for a simplified FileDialog 
window.

--
assignee:  -> terry.reedy
components: +IDLE
nosy: +rhettinger, terry.reedy
priority: normal -> high

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40553] Python 3.8.2 Mac freezing/not responding when saving new programs

2020-05-07 Thread Zain Said


New submission from Zain Said :

What I'm currently using: 
Mid 2012 13'' MacBook Pro OS Catalina 10.15.4
Python 3.8.2

I'm having an issue with saving a new python program. When I go to "save as" a 
program python seems to freeze/not . The only way I've been able to get python 
working again is to "Force Quit" the existing process and reopen IDLE. Running 
and writing existing programs seems to be working fine.

--
messages: 368375
nosy: Zain
priority: normal
severity: normal
status: open
title: Python 3.8.2 Mac freezing/not responding when saving new programs
type: crash
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue40553>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26353] IDLE: Saving Shell should not add \n

2019-11-13 Thread Zackery Spytz


Zackery Spytz  added the comment:

Thank you, Terry, for modifying the PR and merging it.

--
nosy: +ZackerySpytz

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26353] IDLE: Saving Shell should not add \n

2019-11-12 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26353] IDLE: Saving Shell should not add \n

2019-11-12 Thread miss-islington


miss-islington  added the comment:


New changeset 8ce1a9ce038d1a5fda03ae76964002857a2a52f9 by Miss Islington (bot) 
in branch '3.8':
bpo-26353: IDLE adds an unneeded newline when saving a shell window (GH-17103)
https://github.com/python/cpython/commit/8ce1a9ce038d1a5fda03ae76964002857a2a52f9


--
nosy: +miss-islington, miss-islington

___
Python tracker 
<https://bugs.python.org/issue26353>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26353] IDLE: Saving Shell should not add \n

2019-11-12 Thread miss-islington


miss-islington  added the comment:


New changeset 177b12682cad7edf9cdea91382acc4232c0167e6 by Miss Islington (bot) 
in branch '3.7':
bpo-26353: IDLE adds an unneeded newline when saving a shell window (GH-17103)
https://github.com/python/cpython/commit/177b12682cad7edf9cdea91382acc4232c0167e6


--
nosy: +miss-islington

___
Python tracker 
<https://bugs.python.org/issue26353>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26353] IDLE: Saving Shell should not add \n

2019-11-12 Thread miss-islington


Change by miss-islington :


--
pull_requests: +16625
pull_request: https://github.com/python/cpython/pull/17119

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26353] IDLE: Saving Shell should not add \n

2019-11-12 Thread Terry J. Reedy


Terry J. Reedy  added the comment:


New changeset c8b53dc3d8f721ed8519aa5a35530a42fbfb9424 by Terry Jan Reedy 
(Zackery Spytz) in branch 'master':
bpo-26353: IDLE adds an unneeded newline when saving a shell window (GH-17103)
https://github.com/python/cpython/commit/c8b53dc3d8f721ed8519aa5a35530a42fbfb9424


--

___
Python tracker 
<https://bugs.python.org/issue26353>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26353] IDLE: Saving Shell should not add \n

2019-11-12 Thread miss-islington


Change by miss-islington :


--
pull_requests: +16624
pull_request: https://github.com/python/cpython/pull/17118

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26353] IDLE: Saving Shell should not add \n

2019-11-11 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

Zachary determined that the issue is that writing calls 
iomenu.IOBinding.fixlastline, which unconditionally adds \n at the end if there 
is one.  That is not needed for the Shell and wrong when it ends with a prompt, 
which is the normal case.

--
versions: +Python 3.7, Python 3.8, Python 3.9 -Python 3.5, Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26353] IDLE: Saving Shell should not add \n

2019-11-09 Thread Zackery Spytz


Change by Zackery Spytz :


--
keywords: +patch
pull_requests: +16609
stage: test needed -> patch review
pull_request: https://github.com/python/cpython/pull/17103

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38598] IDLE: Disable F5, etc, in Shell, even after saving

2019-10-26 Thread Terry J. Reedy


New submission from Terry J. Reedy :

When the Shell is active, the Run menu is disabled, but its shortcuts are not.  
These are F5 Run Module, Shift-F5 Run ... Custom, and Alt-X Check Module.  If 
Shell has not been saved, the shortcuts do nothing, but once Shell has been 
saved, they try to compile the entire shell session.

The result is that the '3' in 'Python 3.8 ...' on the first line is highlighted 
as an error and the SyntaxError box pops up.  When the box is dismissed, the 
cursor is placed after the '3'.

Instead of calling compile, IDLE should beep and continue.

--
assignee: terry.reedy
components: IDLE
messages: 355432
nosy: terry.reedy
priority: normal
severity: normal
stage: needs patch
status: open
title: IDLE: Disable F5, etc, in Shell, even after saving
type: behavior
versions: Python 3.7, Python 3.8, Python 3.9

___
Python tracker 
<https://bugs.python.org/issue38598>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: No option available for saving files

2019-06-07 Thread Terry Reedy

On 6/7/2019 10:51 AM, Calvin Spealman wrote:

The python shell is good for experimenting and testing some things out, but
you are right it isn't for writing programs you actually re-use and run
later. You can use any text editor you want, Visual Studio Code and Sublime
Text are both popular, but anything will do at all. There is also a simple
editor with integration for running Python included in the Python Windows
installer, called IDLE. You should be able to find that in your start menu.

On Fri, Jun 7, 2019 at 4:24 AM Shreya Joshi 
wrote:


Hi ma’am/sir,
I’ve started using python Shell 3.6.8-32 bit executable installer on
windows OS. But there is no option to save or open a new file. This gives
an output after every line. But, I want to work on longer codes to execute
programs.

Am I using the right interface? Please help.


An interactive shell is for experimentation a statement at a time.
You need an editor for longer code.  IDLE has both.  You can save its 
Shell session to a file for later review or extraction of code that worked.



Here is a screenshot…


This is a text only mailing list with no attachments allowed, certainly 
no images.



--
Terry Jan Reedy


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


Re: No option available for saving files

2019-06-07 Thread Calvin Spealman
The python shell is good for experimenting and testing some things out, but
you are right it isn't for writing programs you actually re-use and run
later. You can use any text editor you want, Visual Studio Code and Sublime
Text are both popular, but anything will do at all. There is also a simple
editor with integration for running Python included in the Python Windows
installer, called IDLE. You should be able to find that in your start menu.

On Fri, Jun 7, 2019 at 4:24 AM Shreya Joshi 
wrote:

> Hi ma’am/sir,
> I’ve started using python Shell 3.6.8-32 bit executable installer on
> windows OS. But there is no option to save or open a new file. This gives
> an output after every line. But, I want to work on longer codes to execute
> programs.
>
> Am I using the right interface? Please help.
> Here is a screenshot…
>
> Sent from Mail for Windows 10
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>


-- 

CALVIN SPEALMAN

SENIOR QUALITY ENGINEER

cspea...@redhat.com  M: +1.336.210.5107
[image: https://red.ht/sig] 
TRIED. TESTED. TRUSTED. 
-- 
https://mail.python.org/mailman/listinfo/python-list


No option available for saving files

2019-06-07 Thread Shreya Joshi
Hi ma’am/sir,
I’ve started using python Shell 3.6.8-32 bit executable installer on windows 
OS. But there is no option to save or open a new file. This gives an output 
after every line. But, I want to work on longer codes to execute programs. 

Am I using the right interface? Please help.
Here is a screenshot…

Sent from Mail for Windows 10

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


Re: I am facing problem in saving my file.

2018-12-16 Thread Abdur-Rahmaan Janhangeer
error message?

Abdur-Rahmaan Janhangeer
Mauritius
-- 
https://mail.python.org/mailman/listinfo/python-list


I am facing problem in saving my file.

2018-12-16 Thread mallickaman2003



Sent from Mail for Windows 10

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


Re: Saving application configuration to the ini file respecting order of sections/options and providing mechanism for (nested) complex objects

2018-08-22 Thread zljubisic
Thanks. As I can see python 3.7 is the best option.
Thank you very very muchs for the code as well.

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


Re: Saving application configuration to the ini file respecting order of sections/options and providing mechanism for (nested) complex objects

2018-08-21 Thread Peter Otten
zljubi...@gmail.com wrote:

> 1. saving json will result in unordered ini file. It could be solved by
> using OrderedDict that will than with json.dumps be saved to file in the
> same order as options are added to the ordered dict.

dict-s are guaranteed to keep insertion order in Python 3.7, see

https://docs.python.org/dev/whatsnew/3.7.html#summary-release-highlights

> 2. there is a problem with datatime values because json format serialize
> everything to string. I have found the solution on page
> https://gist.github.com/abhinav-upadhyay/5300137, but I dislike the idea
> that datetime is represented as unordered dict. When you have to change
> datetime manually in the ini file by using text editor, you first have to
> sort year,month,day... in order to be sure that you are setting correct
> date.

You're free to pick whatever serialisation you like:

$ cat datetimedecoder_isoformat.py
from datetime import datetime
import json
import re


def dict_to_object(d):
if d.get("__type__") != "datetime":
return d
return datetime(*map(int, re.split("[-T:.]", d["isovalue"])))


def default(obj):
if isinstance(obj, datetime):
return {
'__type__': 'datetime',
'isovalue': obj.isoformat()
}
raise TypeError


original = {'name': 'foo', 'type': 'bar', 'date': datetime.now()}
print("original:", original)

serialized = json.dumps(original, default=default, indent=4)
print("serialized:", serialized)

reloaded = json.loads(serialized, object_hook=dict_to_object)
print("reloaded obj:", reloaded)

assert original == reloaded

$ python3 datetimedecoder_isoformat.py 
original: {'date': datetime.datetime(2018, 8, 21, 19, 25, 16, 852379), 
'type': 'bar', 'name': 'foo'}
serialized: {
"date": {
"__type__": "datetime",
"isovalue": "2018-08-21T19:25:16.852379"
},
"type": "bar",
"name": "foo"
}
reloaded obj: {'date': datetime.datetime(2018, 8, 21, 19, 25, 16, 852379), 
'type': 'bar', 'name': 'foo'}


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


Saving application configuration to the ini file respecting order of sections/options and providing mechanism for (nested) complex objects

2018-08-21 Thread zljubisic



Hi,

I am looking for a way to save ini file with application section/option 
combination. Something like the following:

[Default]
ROOT_DIR= /home/...
RUN = True
COUNTER = 5
LAST_VALUE = 5.6
TEST_FILES_LIST=['a.txt', 'b.txt', 'c.txt']
TEST_FILES_DICT={'CASE1' : ['a.txt', 'b.txt'], 'CASE2': ['c.txt']}

[Dates]
CREATE_DATE="2018-01-01"

[DateTimes]
LAST_MODIFIED_DATE="2018-01-01 14:23:45"


For that purpose I decided to use json as a quite readable fomat that can be 
edited with external text editor.
So I have created dict with all options hoping that I will be able to save it 
with json.dumps and read it with json.loads, but I have run to several problems:

1. saving json will result in unordered ini file. It could be solved by using 
OrderedDict that will than with json.dumps be saved to file in the same order 
as options are added to the ordered dict.

2. there is a problem with datatime values because json format serialize 
everything to string. I have found the solution on page 
https://gist.github.com/abhinav-upadhyay/5300137, but I dislike the idea that 
datetime is represented as unordered dict. When you have to change datetime 
manually in the ini file by using text editor, you first have to sort 
year,month,day... in order to be sure that you are setting correct date. 

3. reading with json.loads will get unordered dict again, so new save will be 
unordered.


Maybe json/(un)OrderedDict is not a proper tool for what I am trying to do. 
How you are saving your (nested) configuration to the ini file?

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


Problem in extracting and saving multi-dimensional time series data from netcdf file to csv file

2018-04-17 Thread shalu . ashu50
Hi All,

I am using winpython spyder 3.6. I am trying to extract a variable with their 
time series values (daily from 1950 to 2004). The data structure is as follows:


Dimensions: (bnds: 2, lat: 90, lon: 144, time: 20075)
Coordinates:
  * lat (lat) float64 -89.0 -87.0 -85.0 -83.0 -81.0 -79.0 -77.0 ...
  * lon (lon) float64 1.25 3.75 6.25 8.75 11.25 13.75 16.25 18.75 ...
  * time(time) datetime64[ns] 1950-01-01T12:00:00 ...
Dimensions without coordinates: bnds
Data variables:
time_bnds   (time, bnds) datetime64[ns] ...
lat_bnds(time, lat, bnds) float64 ...
lon_bnds(time, lon, bnds) float64 ...
clt (time, lat, lon) float32 ...

Now I am extracting "clt" variable values based on my area of interest using 
lat/long boxes 

(latbounds = [ -13.0 , 31.0 ]# 22 grid numbers
lonbounds = [ 89.75 , 151.25 ]#26 grid numbers

My code is here:

import netCDF4
import xarray as xr
import numpy as np
import csv
import pandas as pd
from pylab import *
import datetime

# NetCDF4-Python can read a remote OPeNDAP dataset or a local NetCDF file:
nc = 
netCDF4.Dataset('clt_day_GFDL-CM3_historical_r1i1p1_19500101-20041231.nc.nc')
nc.variables.keys()


lat = nc.variables['lat'][:]
lon = nc.variables['lon'][:]
time_var = nc.variables['time']
dtime = netCDF4.num2date(time_var[:],time_var.units)

lat_bnds, lon_bnds = [-13.0 , 31.0], [89.75 , 151.25]
# determine what longitude convention is being used [-180,180], [0,360]
print (lon.min(),lon.max())
print (lat.min(),lat.max())

# latitude lower and upper index
latli = np.argmin( np.abs( lat - lat_bnds[0] ) )
latui = np.argmin( np.abs( lat - lat_bnds[1] ) ) 


# longitude lower and upper index
lonli = np.argmin( np.abs( lon - lon_bnds[0] ) )
lonui = np.argmin( np.abs( lon - lon_bnds[1] ) )  
print(lat)

clt_subset = nc.variables['clt'][:,latli:latui , lonli:lonui]

upto here I am able to extract the data but I am not able to save these values 
in csv file. I am also able to save values for one location but when I am going 
with multi-dimentional extracted values so it is giving an error

when i am executing this:

hs = clt_subset[istart:istop,latli:latui , lonli:lonui]
tim = dtime[istart:istop]
print(tim)
# Create Pandas time series object
ts = pd.Series(hs,index=tim,name=clt_subset)

Error: - 

ts = pd.Series(hs,index=tim,name=clt_subset)
Traceback (most recent call last):

  File "", line 1, in 
ts = pd.Series(hs,index=tim,name=clt_subset)

  File 
"C:\python3\WinPython\python-3.6.5.amd64\lib\site-packages\pandas\core\series.py",
 line 264, in __init__
raise_cast_failure=True)

  File 
"C:\python3\WinPython\python-3.6.5.amd64\lib\site-packages\pandas\core\series.py",
 line 3275, in _sanitize_array
raise Exception('Data must be 1-dimensional')

Exception: Data must be 1-dimensional 

Suggestions would be appreciated. Thanks
Vishu
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue29216] Space saving step for the LRU cache

2018-01-29 Thread Raymond Hettinger

Raymond Hettinger  added the comment:

I've lost interest in this.

--
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31988] Saving bytearray to binary plist file doesn't work

2017-12-25 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

Fixed in issue32072.

--
resolution:  -> duplicate
stage:  -> resolved
status: open -> closed
superseder:  -> Issues with binary plists

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31988] Saving bytearray to binary plist file doesn't work

2017-11-10 Thread Serhiy Storchaka

Change by Serhiy Storchaka :


--
assignee:  -> serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31988] Saving bytearray to binary plist file doesn't work

2017-11-08 Thread Serhiy Storchaka

New submission from Serhiy Storchaka <storchaka+cpyt...@gmail.com>:

>>> import plistlib
>>> plistlib.dumps(bytearray(), fmt=plistlib.FMT_BINARY)
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/serhiy/py/cpython/Lib/plistlib.py", line 962, in dumps
dump(value, fp, fmt=fmt, skipkeys=skipkeys, sort_keys=sort_keys)
  File "/home/serhiy/py/cpython/Lib/plistlib.py", line 955, in dump
writer.write(value)
  File "/home/serhiy/py/cpython/Lib/plistlib.py", line 703, in write
self._flatten(value)
  File "/home/serhiy/py/cpython/Lib/plistlib.py", line 741, in _flatten
if (type(value), value) in self._objtable:
TypeError: unhashable type: 'bytearray'

--
components: Library (Lib)
messages: 305921
nosy: ronaldoussoren, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Saving bytearray to binary plist file doesn't work
type: behavior
versions: Python 3.6, Python 3.7

___
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31988>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26353] IDLE: Saving Shell should not add \n

2017-06-19 Thread Terry J. Reedy

Changes by Terry J. Reedy :


--
assignee:  -> terry.reedy
components: +IDLE

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29216] Space saving step for the LRU cache

2017-01-09 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Ah, there is a wart in the optimization in Python implementation. If call a 
cached function with multiple integer arguments and with equivalent float 
arguments, the second call will return a cached result. But if call with single 
integer and float arguments, both calls will be cached separately.

>>> import functools
>>> @functools.lru_cache()
... def f(*args):
... return args
... 
>>> f(1, None)
(1, None)
>>> f(1.0, None)
(1, None)
>>> f.cache_info()
CacheInfo(hits=1, misses=1, maxsize=128, currsize=1)
>>> f.cache_clear()
>>> f(1)
(1,)
>>> f(1.0)
(1.0,)
>>> f.cache_info()
CacheInfo(hits=0, misses=2, maxsize=128, currsize=2)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29216] Space saving step for the LRU cache

2017-01-09 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

The first patch fails with e.g. tuple subclasses.

The optimization is correct only for types not comparable with tuples. Tuple 
subclasses are comparable, and classes with custom __eq__ can be comparable. 
Thus the optimization should be used only for exact builtin types that are 
known not comparable with tuples. Of course it makes sense only for hashable 
types.

First than commit something like the second patch I would gather statistics. 
What are the most used types of the single positional argument of lru-cached 
functions? Is it worth to apply the optimization for bytes or None? Checking 
type in C is cheaper than in Python, we can use more types.

--
assignee: serhiy.storchaka -> rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29216] Space saving step for the LRU cache

2017-01-09 Thread Raymond Hettinger

New submission from Raymond Hettinger:

Sync with the space savings optimization in the pure Python code.

I'm unsure whether the best way is to check for an exact tuple or whether to 
just check an exact int/str.

--
assignee: serhiy.storchaka
components: Library (Lib)
files: functools_sync.diff
keywords: patch
messages: 285051
nosy: rhettinger, serhiy.storchaka
priority: low
severity: normal
stage: patch review
status: open
title: Space saving step for the LRU cache
type: resource usage
versions: Python 3.7
Added file: http://bugs.python.org/file46228/functools_sync.diff

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29216>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29216] Space saving step for the LRU cache

2017-01-09 Thread Raymond Hettinger

Changes by Raymond Hettinger :


Added file: http://bugs.python.org/file46229/functools_sync2.diff

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28581] Allow running code without explicitly saving the file.

2016-11-01 Thread Terry J. Reedy

Terry J. Reedy added the comment:

In my additional comment, I explored the idea of running without saving, not 
even to a temp file.

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28581>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28581] Allow running code without explicitly saving the file.

2016-11-01 Thread perilbrain

perilbrain added the comment:

Thanks Terry, I tried searching for a similar issue but failed.

Feels like signing contributor form will take a while.
Meantime please feel free to tweak/improve and implement code in your way (Mine 
is a bit rough solution not even abiding by naming convention), if this is some 
licensing issue.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28581] Allow running code without explicitly saving the file.

2016-11-01 Thread Terry J. Reedy

Terry J. Reedy added the comment:

I agree that this is a problem that needs a solution. Your post gives the 
justification very well.  I already opened #19042 for this issue, so as is our 
usual policy, I am merging this duplicate into that one. 

Thank you for submitting a patch.  To apply it, we need a Contributor 
Agreement.  One can be signed electronically.  See 
https://www.python.org/psf/contrib/.  An '*' will appear after your name once a 
CA has been received and registered.  I will take a good look once this happens.

I the meanwhile, I will add a reference to this issue and patch, as well as 
additional comments, to #19042.

--
resolution:  -> duplicate
stage:  -> resolved
status: open -> closed
superseder:  -> Idle: add option to autosave 'Untitled' edit window
versions: +Python 3.6, Python 3.7 -Python 3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28581] Allow running code without explicitly saving the file.

2016-11-01 Thread perilbrain

New submission from perilbrain:

Current Flow:-
- If you create a new file in idle and try to run it, the editor asks to save 
the file. However if user presses cancel button the code is not executed.

Problem:-
I have been using idle for over 5 years and this behavior is quite 
annoying(along with paste :) !!). We are often required to copy code from 
various sites say some tutorial or code samples which are good for one time 
usage.

Solution:-
If a user presses cancel button then set a flag in IOBinding say "optedTemp", 
save it to a named temporary file, execute the code and close the file. If user 
again runs the code, check for this flag. If it is true then there is no need 
to ask for saving the code and again create the temporary file, execute, close. 
If some one needs to save this code they can use the "save as" menu which sets 
off the optedTemp flag.

Here is the code I propose (check for "#+")

==idlelib/ScriptBinding.py===
# At top
import tempfile  #+

# New definition of functions:-


def _run_module_event(self, event):
filename = self.getfilename()
tempCode = None #+
if not filename:
tempCode = tempfile.NamedTemporaryFile(suffix = ".py") 
#+
filename = tempCode.name #Added***
self.editwin.io.writefile( filename ) #+
self.editwin.io.optedTemp = True #+
#return 'break'
code = self.checksyntax(filename)
..
interp.runcode(code)
if tempCode is not None: #+
tempCode.close() #+
return 'break'

def getfilename(self):
filename = self.editwin.io.filename
if not self.editwin.get_saved():
autosave = idleConf.GetOption('main', 'General',
  'autosave', type='bool')
if autosave and filename:
self.editwin.io.save(None)
elif self.editwin.io.optedTemp: #+
filename = None #+
else:
confirm = self.ask_save_dialog()
self.editwin.text.focus_set()
if confirm:
self.editwin.io.save(None)
filename = self.editwin.io.filename
else:
filename = None
return filename

idlelib/IOBinding.py==

def __init__(self, editwin):
#
self.__id_print = self.text.bind("<>", self.print_window)
self.optedTemp = False #+

def save_as(self, event):
filename = self.asksavefile()
if filename:
if self.writefile(filename):
self.set_filename(filename)
self.set_saved(1)
self.optedTemp = False #+
try:
self.editwin.store_file_breaks()
except AttributeError:


--
assignee: terry.reedy
components: IDLE
messages: 279885
nosy: perilbrain, terry.reedy
priority: normal
severity: normal
status: open
title: Allow running code without explicitly saving the file.
type: enhancement
versions: Python 3.4

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28581>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21140] Idle: saving Shell or an OutputWindow should default to .txt

2016-10-06 Thread Terry J. Reedy

Terry J. Reedy added the comment:

A more drastic change would be to refuse to save OutputWindow and Shell as 
.py(w,o) files.  #28365 is about a beginner who apparently save a short Shell 
session as .py, quit IDLE, loaded the saved session in an editor, and tried to 
run it.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21140] Idle: saving Shell or an OutputWindow should default to .txt

2016-10-05 Thread Terry J. Reedy

Terry J. Reedy added the comment:

I am closing #28365 in favor of this.  As noted there, Shell is a subclass of 
OutputWindow is a subclass of EditorWindow, so Shell should inherit new 
behavior from OutputWindow instead of both from EW.

Change to the patch: I think .py should not even be a selectable option as 
Shell cannot be edited down to code, and it would make no sense to do so.  And 
anyone who did want to save as .py could select 'all types' and type '.py' 
explicitly.

I was thinking that filetype should be set in OutputWindow, but that does not 
include text files in an editor window (with 
editwin.ispythonsource(self.filename) False).  Another reason is that I want to 
change the editor class structure.

Currently. the editor window used for all files is the confusingly named 
PyShellEditorWindow in pyshell.py, which adds breakpoints to EditorWindow.  In 
long run, EditorWindow should be used for non-python editing.  The current 
PyShellEditorWindow should become PythonEditor and have all the attributes and 
methods specific to python code.  Then EditorWindow.filetypes would have .txt 
and *.* and .py would be added in PythonEditor.  It would also, then, not be 
necessary to disable code stuff in OutputWindow (like the Run menu).  (In fact, 
it might turn out that EditorWindow and OutputWindow would be the same, a base 
TextEditor

--
assignee:  -> terry.reedy
stage: needs patch -> patch review
versions: +Python 3.6, Python 3.7 -Python 2.7, Python 3.4, Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27965] Automatic .py extension when saving with IDLE on OSX

2016-09-06 Thread Terry J. Reedy

Changes by Terry J. Reedy <tjre...@udel.edu>:


--
title: automatic .py extension -> Automatic .py extension when saving with IDLE 
on OSX
type:  -> behavior

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue27965>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: saving octet-stream png file

2016-08-22 Thread Jon Ribbens
On 2016-08-22, Larry Martell  wrote:
> On Mon, Aug 22, 2016 at 1:25 PM, Jon Ribbens  
> wrote:
>> On 2016-08-22, Larry Martell  wrote:
>>> (Pdb) type(request.POST[key])
>>>
>>> (Pdb) request.encoding = "iso-8859-1"
>>> (Pdb) type(request.POST[key])
>>> *** MultiValueDictKeyError:
>>> "u'right-carotidartery:63B2E474-D690-445F-B92A-31EBADDC9D93.png'"
>>
>> Sounds like you should be filing a bug report with Django.
>
> Turns out that is expected behavior -- request.encoding clears
> existing GET/POST data. Not sure how it's useful to set that then.

Yeah it clears the cached parsed data, but when you fetch a value
afterwards it should automatically recalculate the data, not fail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: saving octet-stream png file

2016-08-22 Thread Larry Martell
On Mon, Aug 22, 2016 at 1:25 PM, Jon Ribbens  wrote:
> On 2016-08-22, Larry Martell  wrote:
>> On Sun, Aug 21, 2016 at 5:24 PM, Jon Ribbens  
>> wrote:
>>> On 2016-08-19, Larry Martell  wrote:
 fd.write(request.POST[key])
>>>
>>> You could try:
>>>
>>>   request.encoding = "iso-8859-1"
>>>   fd.write(request.POST[key].encode("iso-8859-1"))
>>>
>>> It's hacky and nasty and there might be a better "official" method
>>> but I think it should work.
>>
>> For some reason that messes up the request structure:
>>
>> (Pdb) type(request.POST[key])
>>
>> (Pdb) request.encoding = "iso-8859-1"
>> (Pdb) type(request.POST[key])
>> *** MultiValueDictKeyError:
>> "u'right-carotidartery:63B2E474-D690-445F-B92A-31EBADDC9D93.png'"
>
> Sounds like you should be filing a bug report with Django.

Turns out that is expected behavior -- request.encoding clears
existing GET/POST data. Not sure how it's useful to set that then.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: saving octet-stream png file

2016-08-22 Thread Wildman via Python-list
On Mon, 22 Aug 2016 13:21:43 -0400, Larry Martell wrote:

> On Fri, Aug 19, 2016 at 4:51 PM, Lawrence D’Oliveiro
>  wrote:
>> On Saturday, August 20, 2016 at 6:03:53 AM UTC+12, Terry Reedy wrote:
>>>
>>> An 'octet' is a byte of 8 bits.
>>
>> Is there any other size of byte?
> 
> Many, many years ago, probably c. 1982 my Dad came into my house and
> saw a Byte Magazine laying on the coffee table. He asked "What is a
> byte?" I replied "Half a word." He then asked "What is the other half
> of the word?" I said "That is also a byte." He thought for a moment,
> then said "So the full word is 'byte byte'?"

LOL!  Did you explain to him that a full word could also be
'nibble nibble nibble nibble' or 'bit bit bit bit bit bit
bit bit bit bit bit bit bit bit bit bit'?

-- 
 GNU/Linux user #557453
The cow died so I don't need your bull!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: saving octet-stream png file

2016-08-22 Thread Jon Ribbens
On 2016-08-22, Larry Martell  wrote:
> On Sun, Aug 21, 2016 at 5:24 PM, Jon Ribbens  
> wrote:
>> On 2016-08-19, Larry Martell  wrote:
>>> fd.write(request.POST[key])
>>
>> You could try:
>>
>>   request.encoding = "iso-8859-1"
>>   fd.write(request.POST[key].encode("iso-8859-1"))
>>
>> It's hacky and nasty and there might be a better "official" method
>> but I think it should work.
>
> For some reason that messes up the request structure:
>
> (Pdb) type(request.POST[key])
>
> (Pdb) request.encoding = "iso-8859-1"
> (Pdb) type(request.POST[key])
> *** MultiValueDictKeyError:
> "u'right-carotidartery:63B2E474-D690-445F-B92A-31EBADDC9D93.png'"

Sounds like you should be filing a bug report with Django.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: saving octet-stream png file

2016-08-22 Thread Larry Martell
On Fri, Aug 19, 2016 at 4:51 PM, Lawrence D’Oliveiro
 wrote:
> On Saturday, August 20, 2016 at 6:03:53 AM UTC+12, Terry Reedy wrote:
>>
>> An 'octet' is a byte of 8 bits.
>
> Is there any other size of byte?

Many, many years ago, probably c. 1982 my Dad came into my house and
saw a Byte Magazine laying on the coffee table. He asked "What is a
byte?" I replied "Half a word." He then asked "What is the other half
of the word?" I said "That is also a byte." He thought for a moment,
then said "So the full word is 'byte byte'?"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: saving octet-stream png file

2016-08-22 Thread Larry Martell
On Mon, Aug 22, 2016 at 10:36 AM, Larry Martell  wrote:
> On Fri, Aug 19, 2016 at 4:24 PM, Chris Kaynor  
> wrote:
>> On Fri, Aug 19, 2016 at 12:00 PM, Larry Martell 
>> wrote:
>>
>>> On Fri, Aug 19, 2016 at 1:24 PM, Chris Angelico  wrote:
>>> > On Sat, Aug 20, 2016 at 3:10 AM, Larry Martell 
>>> wrote:
>>> >> I have some python code (part of a django app) that processes a
>>> >> request that contains a png file. The request is send with
>>> >> content_type = 'application/octet-stream'
>>> >>
>>> >> In the python code I want to write this data to a file and still have
>>> >> it still be a valid png file.
>>> >>
>>> >> The data I get looks like this:
>>> >>
>>> >> u'\ufffdPNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x01\ufffd\
>>> x00\x00\x01\ufffd
>>> >> ..'
>>> >>
>>> >> If I try and write that to a file it fails with a UnicodeEncodeError.
>>> >> If I write it with encode('utf8') it writes the file, but then it's no
>>> >> longer a valid png file.
>>> >>
>>> >> Anyone know how I can do this?
>>> >
>>> > At that point, you've already lost information. Each U+FFFD (shown as
>>> > "\ufffd" above) is a marker saying "a byte here was not valid UTF-8"
>>> > (or whatever was being used). Something somewhere took the .png file's
>>> > bytes and tried to interpret them as text, which they're not.
>>> >
>>> > What sent you that data? How did you receive it?
>>>
>>> The request is sent by a client app written in C++ with Qt. It's
>>> received by a django based server. I am trying to port a falcon server
>>> to django. The falcon server code did this:
>>>
>>> form = cgi.FieldStorage(fp=req.stream, environ=req.env)
>>>
>>> and then wrote the png like this:
>>>
>>> fd.write(form[key].file.read())
>>>
>>> Whereas in the django server I am doing:
>>>
>>> fd.write(request.POST[key])
>>>
>>> I've never used the cgi module. I guess I can try that. I've written a
>>> lot with django but never had to receive a PNG file.
>>>
>>>
>> I don't know Django, however a quick search makes it seem like you might
>> need to use request.FILES[key] (1) rather than request.POST[key]. You may
>> also be able to use request.POST if you set request.encoding first (2). If
>> both of those fail, you may need to use request.body and parse the HTTP
>> form data manually, though I'd imagine there is an easier way.
>>
>> [1]
>> https://docs.djangoproject.com/en/1.10/ref/request-response/#django.http.HttpRequest.FILES
>>
>> [2]
>> https://docs.djangoproject.com/en/1.10/ref/request-response/#django.http.HttpRequest.encoding
>
> Thanks for the reply. When I get the request, request.FILES is empty.
> Yet the content type is multipart/form-data and the method is POST:
>
> (Pdb) print request.META['CONTENT_TYPE']
> multipart/form-data;
> boundary="boundary_.oOo._NzEwNjIzMTM4MTI4NjUxOTM5OQ==MTY2NjE4MDk5Nw=="
>
> (Pdb) print request.META['REQUEST_METHOD']
> POST
>
> (Pdb) print request.FILES
> 
>
> Tried setting request.encoding, but that messes up the request structure:
>
> (Pdb) type(request.POST[key])
> 
> (Pdb) request.encoding = "iso-8859-1"
> (Pdb) type(request.POST[key])
> *** MultiValueDictKeyError:
> "u'right-carotidartery:63B2E474-D690-445F-B92A-31EBADDC9D93.png'"


Thanks to everyone for they replied. I solved this by changing the
client to set the file and filename fields each part of the multipart
and then I was able it iterate through request.FILES and successfully
write the files as PNG.
-- 
https://mail.python.org/mailman/listinfo/python-list


  1   2   3   4   5   6   >