I find that Jupyter notebooks are stored in .json format.
How can I access this (read only) while inside of the notebook itself?
I want to programmatically get the name of the notebook I am currently working in as a string.
EDIT:
Just want to clarify that I know of the solutions using ipynbname and ipyparams, and I am looking for alternate solutions. Thanks all.
for your particular use case you might want to use a package called ipyparams
You can import it at the top of your file and get your file's name as such:
import ipyparams
notebook_name = ipyparams.notebook_name
Related
I have a problem. Let's say I have a website (e.g. www.google.com). Is there any way to create a file with a .url extension linking to this website in python? (I am currently looking for a flat, and I am trying to save shortcuts on my hard drive only to apartment offers posted online matching my expectations ) I've tried to use the os and requests module to create such files, but with no success. I would really appreciate the help. (I am using python 3.9.6 on Windows 10)
This is pretty straightforward. I had no idea what .URL files were before seeing this post, so I decided to drag its URL to my desktop. It created a file with the following contents which I viewed in Notepad:
[InternetShortcut]
URL=https://stackoverflow.com/questions/68304057/internet-shortcut-in-python
So, you just need to write out the same thing via Python, except replace the URL with the one you want:
test_url = r'https://www.google.com/'
with open('Google.url','w') as f:
f.write(f"""[InternetShortcut]
URL={test_url}
""")
With regards to your current attempts:
I've tried to use os and requests module to create such file
It's not clear what you're using requests or os for, since you didn't provide a Minimal Reproduceable Example of what you'd tried so far; so, if there's a more complex element to this that you didn't specify, such as automatically generating the file while you're in your browser, or something like that, then you need to update your question to include all of your requirements.
I'm currently working with cytoscape and created some session file.
Then I'd like to access this file in python and get its result as an image - I'd especially like to sort it with some particular shared name when I'm requesting a result, meaning the result changes upto sorting word. Thanks.
There is a python library that faciliatates working with CyREST in Python. You should be able to do just about anything you can do in Cytoscape from Python. Here's the manual: https://py2cytoscape.readthedocs.io/en/latest/
And here are some of the steps you are looking for:
cyclient.session.open()
cyclient.network.list()
cyclient.view.export()
Recently followed a short Python bootcamp and have been trying to work on it myself a bit more, but get stuck at the start. We need to upload the data, but for some reason I can't get it to work. In the example it was done like this:
Correct way apparently
So I figured it was just about the file path, so tried to copy that but don't get it to work
My wrong attempt
Any help would be thoroughly appreciated!
Did you try saving the notebook in the same directory where the CSV file exists and use a relative path to import the CSV?
data/titatic.csv
or
titatic.csv
I'm working on a online server, and I need all my list and dict saved. What would be the best and quickest way to approach this?
I tried importing the data, and it works to load the data. But how can I update the imported file?
I think you can use pickle/cPickle module to save and load the date, which are built-in module and easy to use.
I am not very sure the meaning of update import file, what about rewrite the content back to the file after updating in the program?
Does anyone know of a way of accessing MS Excel from Python? Specifically I am looking to create new sheets and fill them with data, including formulae.
Preferably I would like to do this on Linux if possible, but can do it from in a VM if there is no other way.
xlwt and xlrd can read and write Excel files, without using Excel itself:
http://www.python-excel.org/
Long time after the original question, but last answer pushed it top of feed again. Others might benefit from my experience using python and excel.
I am using excel and python quite bit. Instead of using the xlrd, xlwt modules directly, I normally use pandas. I think pandas uses these modules as imports, but i find it much easier using the pandas provided framework to create and read the spreadsheets. Pandas's Dataframe structure is very "spreadsheet-like" and makes life a lot easier in my opinion.
The other option that I use (not in direct answer to your problem) is DataNitro. It allows you to use python directly within excel. Different use case, but you would use it where you would normally have to write VBA code in Excel.
there is Python library to read/write Excel 2007 xlsx/xlsm files http://pythonhosted.org/openpyxl/
I wrote python class that allows working with Excel via COM interface in Windows http://sourceforge.net/projects/excelcomforpython/
The class uses win32com to interact with Excel. You can use class directly or use it as example. A lot of options implemented like array formulas, conditional formatting, charts etc.
It's surely possible through the Excel object model via COM: just use win32com modules for Python. Can't remember more but I once controlled the Media Player through COM from Python. It was piece of cake.
Its actually very simple. You can actually run anything from any program. Just see a way to reach command prompt from that program. In case of Excel, create a user defined function by pressing Alt+F11 and paste the following code.
Function call_cmd()
Shell "CMD /C Notepad", vbNormalFocus
End Function
Now press ctrl+s and go back to Excel, select a cell and run the function =call_cmd(). Here I ran Notepad. In the same way, you can see where python.exe is installed and run it. If you want to pass any inputs to python, then save the cells as file in local directory as csv file and read them in python using os.system().