[Tutor] Variable and a raw string

Joel Goldstick joel.goldstick at gmail.com
Mon Jan 20 15:21:08 EST 2020


On Mon, 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'
>
the following line is causing your problem.  'state' is 'colorado/us
so you are trying to open
/home/user/colorado/us.txt

You could change the / to _ and it should work
> 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



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays


More information about the Tutor mailing list