Python Forum
with statement odd feature
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
with statement odd feature
#3
(May-11-2020, 08:13 PM)Skaperen Wrote: an editing error exposed this to me which i did not find in the reference manual. on a with statement i omitted the "with_item", that is, the as followed by the variable name. but it still worked. i was using the variable f. so, i left it out, and removed it in another with statement. the script still works. maybe, some day, it will break.

is this supposed to happen? is this a Cpython glitch?

#!/usr/bin/env python3
import os,sys
a='~/.'+(sys.argv[0].rsplit('/',1)[1])
try:
 with open(os.path.expanduser(a+'-pre.py')):
  p=[x[:-1] for x in f]
except:
 p="""
import os
from subprocess import call,DEVNULL,PIPE,Popen,run
from sys import stderr,stdin,stdout,version_info
from time import sleep,time as secs
""".splitlines()
try:
 with open(os.path.expanduser(a+'-suf.py')):
  s=[x[:-1] for x in f]
except:
 s=[]
c='\n'.join(p+sys.argv[1:]+s)
if len(sys.argv)>1:os.execvp('/usr/bin/env',['env','python3','-c',c])



well, with all-catching except what else do you expect? It throws an error and the except block is executed always.

By the way, how do you read this code with single space indentation per level? It's a nightmare
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
with statement odd feature - by Skaperen - May-11-2020, 08:13 PM
RE: with statement odd feature - by ndc85430 - May-12-2020, 04:51 AM
RE: with statement odd feature - by buran - May-12-2020, 05:03 AM
RE: with statement odd feature - by Skaperen - May-12-2020, 11:43 PM
RE: with statement odd feature - by buran - May-13-2020, 04:19 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020