How to set path to matplotlib custom style? [closed] - python

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last month.
Improve this question
As per matplotlib documentation:
"You can create custom styles and use them by calling style.use with the path or URL to the style sheet."
I tried:
plt.style.use('/usr/share/mygraph/mystyle.mplstyle')
but it is returning:
ValueError: '/usr/share/mygraph/mystyle.mplstyle' not found in the style library and input is not a valid URL or path. See `style.available` for list of available styles.
Could someone please help me on how to set the path right?
Is there is any other way how to achieve this?
I would like to distribute my custom style in rpm package so it would be tricky to put it in user's home dir.
Setting "MPLCONFIGDIR" environment variable would also work but I would like to avoid this.
Thanks for your help!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
EDIT:
In my impetuosity I forgot to copy the file there. The output error about not valid URL confused me so I thought the whole path is not valid and focused on that. Shame on me!

Maybe it can be useful to future readers to know that there is also the possibility of changing the style folder (you can get the current folder with matplotlib.get_configdir()). According to documentation:
You also can change the directory where Matplotlib looks for the
stylelib/ folder by setting the MPLCONFIGDIR environment variable, see
matplotlib configuration and cache directory locations.

Related

PYQT6.4 QTableWidget.sortItems function, Pycharm is throwing a syntax issue even though syntax follows documentation [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 months ago.
Improve this question
Here is the documentation: QTableWidget.sortItems
This is the function:
PySide6.QtWidgets.QTableWidget.sortItems(column[, order=Qt.AscendingOrder])
The following is my code:
self.notes_current_table_widget.sortItems(column[2, order=Qt.AscendingOrder])
PyCharm displays this as an error, when I try to run I get:
SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?
Syntax error is in regards to: order=Qt.AscendingOrder
I have tried on other QTableWidgets with the same issue. I have verified that the type is QTableWidget. I have updated all packages to the latest within the project. I have checked syntax of lines before and after.
I ran into this issue because I wanted to sort a dataframe and display the dataframe using a QTableWidget. df = dataframe. The dataframe is sorted until adding the df to the QTableWidget. That's when I looked at this QTableWidget.sortItems function. Any thoughts or ideas?
The docs say:
PySide6.QtWidgets.QTableWidget.sortItems(column[, order=Qt.AscendingOrder])
The square brackets here indicate that order is an optional argument, with default value Qt.AscendingOrder. You're not supposed to write the square brackets explicitly.
So, your code should probably look like this:
self.notes_current_table_widget.sortItems(column=2, order=Qt.AscendingOrder)
Or leave out order altogether, as you're using the default value anyway.

os module python is working but the output isn't correct [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I decided to read name files and create soft links for files in python.
I tried to use os.system for create soft links, this creates link files but after opening the link file says "this file not found"
os.system(f'ln -s "./../{movie_name}" "./../sorted/{year}/{movie_name}"')
and use os.symlink(f'./../{filename}',f'./../{filename}.link')
and when open this link file not founded.
Please use os.symlink() to create symlinks instead, don't shell out to ln -s. After all, as it is your problem may be caused by improper quoting (consider a movie name with a quote, for instance).
In addition, remember symlinks can contain relative paths. You can canonicalize the destination path with os.path.realpath():
source_name = os.path.realpath(f"../{movie_name}")
dest_name = f"../sorted/{year}/{movie_name}"
assert os.path.isfile(source_name) # just to be sure!
os.symlink(source_name, dest_name)

Glob returns back an empty list in Python [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
My code:
hi = glob.glob("hi/FEC[0-9][0-9][0-9][0-9][0-9]_[0-9].seq")
I'm using a glob module and I'm trying to get all the path file names but all it returns back is a empty list. I don't know why it keeps doing that. It worked before my code was accidentally erased.
[]
Regardless if the file isn't even there, it still gives me an empty list.
Update:
So the following files I have are
FEC00001_1.seq
FEC00002_1.seq
FEC00002_2.seq
and so on..
Update 2:
So it I just realized that it might have to do something with the wrong folder like you guys said.
Because right now, my script is in "folder1" and all the files I'm trying to access is in "folder2"
/mainfolder/folder1/script.py
/mainfolder/folder2/files im trying to access
glob.glob is done by using the os.listdir() and fnmatch.fnmatch() functions in concert. So it's important that you search at the right place.
Considering your file hierarchy:-
/mainfolder/folder1/script.py
/mainfolder/folder2/files im trying to access
try the following :-
hi = glob.glob("../folder2/FEC[0-9][0-9][0-9][0-9][0-9]_[0-9].seq")

Python help - AttributeError: 'module' object has no attribute 'ArgumentParser' [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I need help with something that should be basic. Using the example from Python.org I am encountering the following error
parser = argparse.ArgumentParser(description='Process some integers.')
AttributeError: 'module' object has no attribute 'ArgumentParser'
import argparse
parser = argparse.ArgumentParser()
A print argparse.__ file__ confirmed that it is calling the correct argparse.py file:
File "C:\Python27\lib\argparse.py", line 86, in
Also I made sure there are no nameclashes withother modules. Infact, just removing everything else from the script still calls this error.
Have tried reinstalling python 2.7.9 with no change.
Help this noob please!
It's because your file name is the same as the module name. Rename your file and try again.
so, I had:
from numpy import *
and I changed this to import numpy and it didn't work.
Then I copied all the test verbatim and made a new .py file and saved it out.
Now it works.
thank you Python. I think i'll stick to C!! :S
I think I know what's wrong. It may be unavailable in the release of Python 2.7 that you're using. Try installing Python 2.7.8 or 2.7.9.
When importing modules, python usually first looks for them in your current Path, and only if it can't find them there, it will then look in the other Python-paths (found in sys.path).
Like Daniel Roche said, You obviously named your script "argparse.py" (thinking this would be a good name for an example on how to use argparse, an intuitive and common mistake, I think) and then basically told your script to import itself (how rude).
... And since your script does not have an "ArgumentParser" method defined, this must of course yield an Error.

Safest and most efficient way retrieve and serve files/images from folder? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Improve this question
Say i have folder in the media directory called /images/year/month/day. I would like to get the image name and path for these images and have a page serve all the images in the directory.
I then have another folder called /files which contains application files. The same structure etc.
All uploads for files are recorded as part of a database. The images are not saved via a database hence i want to read all files from all sub directories under images possibly including the year month date information.
Is it safe to do such a thing and how would i go about doing so? What would i need to look for when doing so.
Thanks
Yes, it's safe to do so, as long as you do proper escaping. You want to make sure you don't allow any directory traversal outside of that root-level media directory so that none of your application files get served.
You can do this with a simple barrier check:
dir_to_serve = os.path.abspath(dir_to_serve) # get full path
if not dir_to_serve.startswith(media_dir): # maybe settings.MEDIA_DIR here?
return # don't ever serve this
# code to serve from path
In Django, you can simply pass a result list from os.walk to your template and loop through it. You may wish to filter out certain file types or directory names in your template that you don't wish to display.

Categories