Category : python-3.8

I have a function that can generate the input for one test and I want to invoke that function for some random number of times to send inputs to my testing_function with @pytest.mark.parametrize ## part that generates inputs needed import numpy as np def generate_proper_list(): return np.random.uniform(low=0.1, high=8.0, size=(np.random.randint(low=1,high=5,size=1)[0],4)) ### I would like to run ..

Read more

Custom typing in Python 3.8 I have: /zoo.py from typing import List class Zoo(object): animals: List /animal.py from zoo import Zoo class Animal(object): zoo: Zoo How do I determine the type of data in the first file without the cyclicity of imports? I want to get the following /zoo.py from typing import List from animal ..

Read more

I’m trying to pip install torch in Python 3.8.6 project by D:myproject> path on Windows 10 OS: PyCharm terminal: Requirement already satisfied: torch in c:usersuserappdatalocalprogramspythonpython38libsite-packages (1.8.0+cpu) Requirement already satisfied: typing-extensions in c:usersasusappdatalocalprogramspythonpython38libsite-packages (from torch) (3.7.4.3) Requirement already satisfied: numpy in c:usersasusappdatalocalprogramspythonpython38libsite-packages (from torch) (1.20.1) but import torch shows Install Packages filed: Installing packages error: Source: ..

Read more

I found this strange behavior that when I use sys.stdout.buffer.write to output some data (without any new line chars) and redirect it to e.g. a file. The file is always empty when running and after I press control-c. import os,sys,itertools try: while True: sys.stdout.buffer.write(b'{$content}’) sys.stdout.buffer.flush() except: pass PS …> .test.py > output.txt sys.stdout.flush() didn’t work ..

Read more

I have the following structure of python code: . ├── my_main.py └── my_pkg ├── my_dep.py ├── my_script.py Both my_main.py and my_script.py should be callable (have a if __name__ == ‘__main__’) section: my_main.py: import my_pkg.my_script if __name__ == ‘__main__’: print(my_pkg.my_script.bar()) and my_script.py: import my_dep def bar(): return my_dep.foo() + 1 if __name__ == ‘__main__’: print(bar()) this ..

Read more