Re: [Tutor] How to convert string to date time format?

2019-07-20 Thread Steven D'Aprano
On Fri, Jul 19, 2019 at 10:44:36PM -0400, C W wrote:
> Hello all,
> 
> I have a date time string that looks like the following.
> 
> 02015-07-01 00:01:44.538420-08:00
> 12015-07-01 00:27:58.717530-08:00
> 22017-07-01 07:07:48.391376-08:00

I assume that the leading number and spaces "0" etc are NOT part of 
the strings.

 
> I have tried the following two different methods, both did not work.
> Method one: pandas
> import pandas as pd
> stamp = pd.to_datetime(my_string, format='%Y%m%d %H:%M:%S')
> 
> Method two: datetime package
> from datetime import datetime
> datetime.strptime(my_string, '%Y-%m-%d %H:%M:%S')
> 
> 
> Are both ways suppose to work?

Not unless the string format matches the actual string. You can't expect 
to convert a string unless it matches the format.


> Also, does it matter if there are decimals
> after seconds?

Of course it matters.

Did you read the error message? The single most important skill for a 
programmer is to READ THE ERROR MESSAGE and pay attention to what it 
tells you went wrong:

py> datetime.strptime('2015-07-01 00:01:44.538420-08:00', '%Y-%m-%d %H:%M:%S')
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python3.5/_strptime.py", line 510, in _strptime_datetime
tt, fraction = _strptime(data_string, format)
  File "/usr/local/lib/python3.5/_strptime.py", line 346, in _strptime
data_string[found.end():])
ValueError: unconverted data remains: .538420-08:00


See how the error message tells you that it couldn't convert the string 
because there is data left over at the end. The first thing to do is 
handle the microseconds.

Googling gets the answer: use "%f" as the code for fractional seconds.

https://duckduckgo.com/?q=strptime+seconds+with+decimals


py> datetime.strptime('2015-07-01 00:01:44.538420-08:00', '%Y-%m-%d 
%H:%M:%S.%f')
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python3.5/_strptime.py", line 510, in _strptime_datetime
tt, fraction = _strptime(data_string, format)
  File "/usr/local/lib/python3.5/_strptime.py", line 346, in _strptime
data_string[found.end():])
ValueError: unconverted data remains: -08:00


Now we're making progress! The error message has changed. Now you just 
need to decide what the "-08:00" part means, and change the format 
string appropriately.



-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Stylometry Help

2019-07-20 Thread Mats Wichmann
On 7/19/19 4:53 AM, ali...@mailbox.org wrote:
> Hello together,
> 
> I try to write a Python tool but after hours of trying , reading and looking 
> for help nothing an no one would help me. So this is my most desperate call 
> for help. I attached the project and my required files. If there is someone 
> who would help me not loosing my scholarship and so beeing excluded from 
> university you'll be my hero.
> 
> 
> Best regards
> 
> Hanna

Hanna, this ia bit over the top.

If you send code - with descriptions of specific problems and what
you've tried, not just a huge blob of code with a non-specific "it
doesn't work" - pepople here will happily try to help.  There are other
places you can look, like Stack Overflow, again it will require asking
targeted questions.

But you really can't expect us, as a band of spare-time volunteers, to
bail you out of a real or imagined situation where if you can't solve
the problem you'll be sent down. If it's that dire, there is usually
paid tutoring available at most institutions or hanging around them, and
potential loss of a scholarship ought to make that investment worthwhile.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Imported Code

2019-07-20 Thread Albert-Jan Roskam


On 25 Jun 2019 15:50, stephen.m.sm...@comcast.net wrote:

Introduction:

I have written a 'program' that does some reasonable screen scraping off of
a specific website. The program has gotten too large so I have tried to
segment it into logical pieces (tkinter logic as a start) but I am having
problems. Specifically I need to pass several dictionaries to the module
(imported code) that validates some user selection and into the code that
navigates through the website.

》》 Hi, not sure if you could use it here, but I was triggered by the term 
"validation":
* Tkinter allows you to define a validationcommand, 
https://stackoverflow.com/questions/4140437/interactively-validating-entry-widget-content-in-tkinter
* You can also define tracers. These are functions that are triggered when a 
Tkinter var (e.g  StringVar) is changed.
* You can also bind events to a function. For example a  event from 
an Entry checks the entry contents and colors it red if it's invalid.

It's been a while since I've used this but those tricks may come in handy!

Albert-Jan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Stylometry Help

2019-07-20 Thread Bob Gailer
On Jul 20, 2019 7:56 AM,  wrote:
>
> Hello together,
>
> I try to write a Python tool but after hours of trying , reading and
looking for help nothing an no one would help me. So this is my most
desperate call for help. I attached the project and my required files.

Unfortunately the tutor list does not forward attachments. If the files are
not too big just include them in the body of the email. Otherwise you'll
have to store them in the cloud and give us a link.

Be sure to reply all so we all get to see your problem.

Bob gailer
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to convert string to date time format?

2019-07-20 Thread johnf
Try python-dateutil - I found it to be one of the better python modules 
for dealing with dates.  You may have to replace or strip some of the 
string.


Johnf


On 7/19/19 7:44 PM, C W wrote:

Hello all,

I have a date time string that looks like the following.

02015-07-01 00:01:44.538420-08:00
12015-07-01 00:27:58.717530-08:00
22017-07-01 07:07:48.391376-08:00

I have tried the following two different methods, both did not work.
Method one: pandas
import pandas as pd
stamp = pd.to_datetime(my_string, format='%Y%m%d %H:%M:%S')

Method two: datetime package
from datetime import datetime
datetime.strptime(my_string, '%Y-%m-%d %H:%M:%S')


Are both ways suppose to work? Also, does it matter if there are decimals
after seconds? Thanks a lot!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] How to convert string to date time format?

2019-07-20 Thread C W
Hello all,

I have a date time string that looks like the following.

02015-07-01 00:01:44.538420-08:00
12015-07-01 00:27:58.717530-08:00
22017-07-01 07:07:48.391376-08:00

I have tried the following two different methods, both did not work.
Method one: pandas
import pandas as pd
stamp = pd.to_datetime(my_string, format='%Y%m%d %H:%M:%S')

Method two: datetime package
from datetime import datetime
datetime.strptime(my_string, '%Y-%m-%d %H:%M:%S')


Are both ways suppose to work? Also, does it matter if there are decimals
after seconds? Thanks a lot!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Stylometry Help

2019-07-20 Thread aliqua
Hello together,

I try to write a Python tool but after hours of trying , reading and looking 
for help nothing an no one would help me. So this is my most desperate call for 
help. I attached the project and my required files. If there is someone who 
would help me not loosing my scholarship and so beeing excluded from university 
you'll be my hero.


Best regards

Hanna
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor