Has anyone implemented type hinting for the specific numpy.ndarray class? Right now, I’m using typing.Any, but it would be nice to have something more specific. For instance if the NumPy people added a type alias for their array_like object class. Better yet, implement support at the dtype level, so tha…
Tag: python
How to change working directory in Jupyter Notebook?
I couldn’t find a place for me to change the working directory in Jupyter Notebook, so I couldn’t use the pd.read_csv method to read in a specific csv document. Is there any way to make it? FYI, I’m using Python3.5.1 currently. Thanks! Answer Running os.chdir(NEW_PATH) will change the workin…
Correct way use type hints / generics to describe arguments of type class (“type”)
This appears to be similar to Type Hinting: Argument Of Type Class, however, the accepted answer there does not actually answer my question, so perhaps the question was expressed incorrectly (?) I have a serialization/deserialization framework that would benefit greatly from [IDE-supported] type hinting. The …
Why does Python assign None if you add a variable to a set while assigning it
Instead of adding a variable to a set correctly, e.g.: I just accidentally coded: While I appreciate that this is not how you should add items to a set, it surprised me that the above resulted in set_to_add_to taking the value None. I couldn’t work out why that would happen: it seems analogous to int_va…
python stock price real time data feed (script debug)
i’m just beginning to learn to code and i want to apologize in advance if this question is trivial. ive been trying to find a way to feed stock market data into python real time and came across this blog http://www.quantatrisk.com/2015/05/07/hacking-google-finance-in-pre-market-trading-python/ Below is …
__init__() got an unexpected keyword argument ‘_job’
I am trying to use scrapyd with scrapy. When I use this the code below it works fine. But when I use it with selenium, it doesn’t My spider never runs. In jobs it gets listed under finished, and on error log I see exceptions.TypeError: __init__() got an unexpected keyword argument ‘_job’. He…
How to return a non-zero exit code on a custom Django command while being able to test it?
I have a Django custom command that can return non-zero exit codes. I’d like to test this command, but the call to sys.exit(1) exits the test runner. Is there a “proper” way to assign the exit code in a custom Django command? My code currently looks like this: Answer I chose to mock the call…
Python program using feedparser slows over time [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 7 years ago. Improve this question I have a Python program which is running in a loop and downloading 20k RSS…
Python: How to encode DNA sequence using binary values?
I would like to convert a file that contained few DNA sequences into binary values which is as follow: FileA.txt Desired output I have tried using this code to solve my problem but the bin output file seem failed to output my desired answer. Can anyone help me? Code Answer Do you want ascii output or binary? …
How can I get the cursor’s position in an ANSI terminal?
I want to get the cursor’s position in a terminal window. I know I can echo -e “33[6n” and read the output -s silently as in this answer, but how can I do this in Python? I’ve tried this contextmanager like this: but it only captures the e[6n (‘x1b[6n’) escape sequence I wr…