Error in goto module [Python]

2024/11/17 16:49:35

Ok, let me start by saying I know that it is bad that I am using the goto module and I shouldn't be and blah blah blah. However, for this specific purpose I need it. Let me also say that I am new to Python so try to avoid complicated answers, thanks!

So with that out of the way let me now explain my issue (I am on Linux). When I run my little program, it runs fine until I hit my first string input. After I type in the string and press enter, it gives me this error:

Traceback (most recent call last):File "main.py", line 16, in <module>empid = input("Example Input: ")File "<string>", line 1, in <module>File "/usr/local/lib/python2.7/dist-packages/goto.py", line 255, in _trace_addToCaches(filename)File "/usr/local/lib/python2.7/dist-packages/goto.py", line 230, in _addToCachesin tokenize.generate_tokens(open(moduleFilename, 'r').readline):
IOError: [Errno 2] No such file or directory: '<string>'

I have tried reinstalling the module, reinstalling python, and I'm not too sure that string would really be incorporated into goto.py anyway.

Thanks,
Cether

EDIT: As requested, here is the code that leads up to the problem:

from goto import *
import time
import sys
import oslabel .start
os.system('clear')
print "Example Printout"exampin = input("Example Input: ")

The error happens when I press enter after I enter the string in that input.

Answer

goto.py is an April Fool's Day joke. Do not ever use it. If you are using it seriously, you are not using Python seriously. However, the source is quite simple, so one can find out why this happens, from a purely academic viewpoint.

goto.py:284 contains the line sys.settrace(_trace). The sys.settrace function is designed to be used by debuggers, and basically "catches" each line of Python before it actually executes, to create these pseudo-syntaxes. The function _trace defined on line 251 assumes that each line of code that is about to be executed has an associated filename, and that filename can be opened.

However, when the input function is run, it executes arbitrary Python code to evaluate, the string. This is a terrible default, but that's what it does, and it was changed in Python 3 to only return a string. When the code is being evaluated, it considers its filename to be <string>. This filename does not exist, so when the _trace function sees the code, it can't open the filename and crashes while "debugging".

The solution: ensure that you are never executing code that doesn't have an existing file associated with it. Avoid eval, input, exec, and anything that evaluates code outside of a file. Use raw_input instead.

https://en.xdnf.cn/q/120179.html

Related Q&A

How to scrape all product review from lazada in python

i currently working on web scraping of data from the lazada site using selenium in python: https://www.lazada.sg/products/loreal-paris-uv-perfect-even-complexion-sunscreen-spf50pa-30ml-i214861100-s325…

How to compare 2 successive row values in a resultset object using python

I have a table issue_logs:id | issue_id | from_status | to_status | up_date | remarks ----+----------+-------------+-----------+----------------------------------+----------…

Getting all possible combination for [1,0] with length 3 [0,0,0] to [1,1,1]

from itertools import combinationsdef n_length_combo(arr, n):# using set to deal# with duplicates return list(combinations(arr, n))# Driver Function if __name__ == "__main__":arr = 01n = 3pri…

Compare values under multiple conditions of one column in Python

I have the following data:data = {"index": [1, 2, 3, 4, 5],"name": ["A", "A", "B", "B", "B"],"type": [s1, s2, s1, s2, s3]…

Python: Tkinter :Dynamically Create Label

I am trying to create Label Dynamically , I am getting invalid Syntax. Can you please help me what i am missing or any alternativecrsr = cnxn.execute(query)row_num=2column_num=0Variable_Number=1for row…

TypeError: str object is not callable when trying to click datepicker

The relevant HTML<div id="datepickerbox" class="ym-gbox-left"><div class="datepick_label"><div id="datepicker" class="hasDatepicker">…

Stanford parser with NLTK produces empty output

I am trying to use the Stanford parser in a small application written in Python with the NLTK interface. I tried the code given below.Everything seems to work right, no errors, Java is launched but I s…

How do you return a list of the matched item in string with regex? [duplicate]

This question already has answers here:Regular expression to match a dot [duplicate](8 answers)Closed 3 years ago.I made this simple functions that searches for emails in the source code of a page , th…

Indentation Error [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable…

open csv file in python to customize dictionary [duplicate]

This question already has answers here:Creating a dictionary from a CSV file(4 answers)Closed 9 years ago.I would like to know to load this csv file:Epitope,ID,Frequency,AssayAVNIVGYSNAQGVDY,123431,27.…