[Tutor] Variable and a raw string
Richard Damon
Richard at Damon-family.org
Mon Jan 20 17:21:39 EST 2020
Does the directory /home/user/colorado exist? (And is writable?)
The function fopen can create the file, but it won’t create the directory.
> On Jan 20, 2020, at 3:15 PM, Alessandro Caudilho <caudilho at cock.li> wrote:
>
> Hello all
>
> my code below:
>
> ============================
> from datetime import datetime
>
> state = 'colorado/us'
>
> with open('/home/user/' + state + '.txt', 'a') as f:
> time = datetime.today().strftime('%Y-%m-%d %H:%M:%S')
> f.write(time)
> f.close()
> ============================
>
> And I get FileNotFoundError: [Errno 2] No such file or directory: "/home/user/colorado/us'.txt"
>
> So how can I create a variable and assign the raw string to it? Are there other solutions for this problem?
>
> --
> Alessandro Caudilho <caudilho at cock.li>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list