Python Forum
visibility/space of variables. Pls help.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
visibility/space of variables. Pls help.
#1
I have two modules only.
the first one - is the main programm, which is using functions from the second module.
The second module consists from functions only
Here is the first module
import requests
from bs4 import BeautifulSoup
import sys
sys.path.append("E:\\Python\\Learning\\Parce_functions")
spisok = []         
_tmpvar = ""        
import F_Hydac_POST
_name_element = "pi3111"
spisok = F_Hydac_POST.start_parce(_name_element)
print("Here is the Hydac list", spisok)
here is the second module
 
def fg_list_bot(_name_element, _output_file):
    _url = "https://www.hydac.com/de-de/nc/service/online-tools/betterfit.html?tx_hybetterfit_pi2%5Baction%5D=search&tx_hybetterfit_pi2%5Bcontroller%5D=Search&cHash=c662ac5f5387b650059f2ede4c291cec"
    # THis line produces an error message
    s = requests.Session()
    _headers = {"User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0"}
    _data = {"tx_hybetterfit_pi2[query]": _name_element}
    r = requests.post(_url, data=_data, headers = _headers)
    with open(_output_file, "w") as f: f.write(r.text)
    print(r.status_code)
    return(r.text)
def start_parce(_name_element):
    _output_file = "IDLE_HYDAC.html"
    _tmpvar = fg_list_bot(_name_element, _output_file)
Here is the error message
 ================= RESTART: E:\Python\Learning\start_parce.py =================
Traceback (most recent call last):
  File "E:\Python\Learning\start_parce.py", line 10, in <module>
    spisok = F_Hydac_POST.start_parce(_name_element)
  File "E:\Python\Learning\Parce_functions\F_Hydac_POST.py", line 81, in start_parce
    _tmpvar = fg_list_bot(_name_element, _output_file)
  File "E:\Python\Learning\Parce_functions\F_Hydac_POST.py", line 5, in fg_list_bot
    s = requests.Session()
NameError: name 'requests' is not defined
Reply
#2
the "second" module has no way to know what you would eventually import in the "first" module
you need to import requests in the second module
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


Possibly Related Threads…
Thread Author Replies Views Last Post
  from global space to local space Skaperen 4 2,269 Sep-08-2020, 04:59 PM
Last Post: Skaperen
  modifying variables in local or global space Skaperen 2 2,158 Aug-14-2019, 07:13 AM
Last Post: Skaperen
  PyMODINIT_FUNC and gcc hidden visibility jock 0 3,416 Feb-01-2018, 03:47 PM
Last Post: jock
  How is space of variables/functions/objects... called? j.crater 4 5,013 Dec-19-2016, 12:24 PM
Last Post: j.crater

Forum Jump:

User Panel Messages

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