When I execute
sp.preview(expression, viewer = “file”, filename = “expression.png”)
SymPy automatically saves the preview in C:\Users\my username.
How do I change the save path?
I'm not sure if there is a canonical way to do this, but you can get the SYMPY_PATH as
from sympy.testing.tests.test_code_quality import SYMPY_PATH
and at least add that as a prefix to your filename (however your system likes paths added). If that works and puts it in the SymPy directory then you can use any path where you would like the file to go.
Related
I am trying to find a solution to load an external data file but from a relative path, so when someone else open my PBIX it will still work on his/her computer.
many thanks.
Relative paths are *not* currently supported by Power BI.
To ease the pain, you can create a variable that contains the path where the files are located, and use that variable to determine the path of each table. That way, you only have to change a single place (that variable) and all the tables will automatically point to the new location.
Create a Blank Query, give it a name (e.g. dataFolderPath) and type in the path where your files are (e.g. C:\Users\augustoproiete\Desktop)
With the variable created, edit each of your tables in the Advanced Editor and concatenate your variable with the name of the file.
e.g. instead of "C:\Users\augustoproiete\Desktop\data.xlsx", change it to dataFolderPath & "\data.xlsx"
You can also vote/watch this feature request to be notified when it gets implemented:
Support relative path to excel/csv sources
You can use also the "Parameters" function.
1. Create a new Parameter like "PathExcelFiles"
Parameter_ScreenShot
Edit your "Source" entry
SourceEntry_ScreenShot
Done !
I don't think this is possible yet.
Please add your support for this idea so the Microsoft Power BI team will be more likely to add this as a new feature.
I couldn't bear the fact that there is no possibility to use relative paths, but finally I had to...
So I tried to find a half-decent acceptable workaround.
Using Python-Script it is at least possible to get access to the users %HOME% directory.
let
PySource = Python.Execute("from pathlib import Path#(lf)import pandas as pd#(lf)dataset = pd.DataFrame([[str(Path.home())]], columns = [1])"),
homeDir = Text.Trim(Lines.ToText(PySource{[Name="dataset"]}[Value][1])),
...
The same should be possible with R-Script but didn't do it.
Anybody knows any better solution to get the %HOME% directory inside "Power" Query? I would be glad to have one.
Then I created two scripts inside my working directory install.bat:
#ECHO OFF
if exist "%HOME%\.pbiTemplatePath\filepath.txt" GOTO :ERROR
#This is are the key commands
mkdir "%HOME%\.pbiTemplatePath"
echo|set /p="%cd%" > "%HOME%\.pbiTemplatePath\filepath.txt"
GOTO :END
#Just a little message box
:ERROR
SET msgboxTitle=There is already another working directory installed.
SET /p msgboxBody=<"%HOME%\.pbiTemplatePath\filepath.txt"
SET tmpmsgbox=%temp%\~tmpmsgbox.vbs
IF EXIST "%tmpmsgbox%" DEL /F /Q "%tmpmsgbox%"
ECHO msgbox "%msgboxBody%",0,"%msgboxTitle%">"%tmpmsgbox%"
WSCRIPT "%tmpmsgbox%"
:END
and uninstall_all.bat:
#ECHO OFF
if exist "%HOME%\.pbiTemplatePath\filepath.txt" RMDIR /S /Q "%HOME%\.pbiTemplatePath\"
So in "Power" BI I did this:
let
PySource = Python.Execute("from pathlib import Path#(lf)import pandas as pd#(lf)dataset = pd.DataFrame([[str(Path.home())]], columns = [1])"),
homeDir = Text.Trim(Lines.ToText(PySource{[Name="dataset"]}[Value][1])),
workingDirFile = Text.Combine({homeDir, ".PbiTemplatePath\filepath.txt"} , "\"),
workingDir = Text.Trim(Lines.ToText(Csv.Document(File.Contents(workingDirFile),[Delimiter=";", Columns=1, QuoteStyle=QuoteStyle.None])[Column1])),
...
Now if my git-repository (containing a "Power" BI-template-file and some config-files saying the template where to load the data from and the install/uninstall-scripts). Install has to be executed once and nobody has to copy and paste any path.
I'd be glad about any suggestion of improvement. It's not the solution Gotham deserves... Gotham deserves a better one.
As mentioned by a few people, you can use a dataset parameter and reference that in your script. What I haven't seen mentioned is that you can change these values using an API call:
https://learn.microsoft.com/en-us/rest/api/power-bi/datasets/update-parameters
Working at the university, I am experiencing the problem of not being able to change config files like "digits" in the tessdata as I do not have admin rights. So I want to run everything from my home, creating patterns, configs and training data files there. Starting my detection like this works fine with the expected output:
tesseract ../pics/hi.png out --tessdata-dir ./tessdata digits
I.e. by setting the path from where I run tesseract. But how can I include this path (best as an absolute one) in the line where pytesser calls tesseract? It looks as follows
args = [tesseract_exe_name, input_filename, output_filename,'nobatch', '/prog/tessdata/configs/digits']
which doesn't work. Using just digits as a path draws the digits file from the common program and file archive which I do not want.
What's the way to include an absolute path here to tell tesseract where to draw the config files from? Or is that not possible? Any hints would be much appreciated!
So I think I found the answer here:
https://docs.python.org/2/library/subprocess.html#subprocess.Popen
import shlex
arg_str = 'tesseract ../pics/hi.png out --tessdata-dir ./tessdata digits'
args = shlex.arg_str
does the job, just need to be seperated strings.
I have a rather large script where I have set a few different files with direct paths. An example would be:
path1 = "C:/temp/"
path2 = "C:/users/<username>/My Documents/test.txt"
Essentially, I would like to set these variables to the file and/or folder path based on a user input. Is it possible to make the user browse to a location and then take that input path and place it into a variable?
Thanks
The tkFileDialog module has methods that allow the user to browse and select directories and files. Namely, askdirectory and askopenfilename.
In brief:
views.py:
def display_path(request):
import os
return HttpResponse("The path is %s" % os.path.abspath("."))
Results in
The path is /var/www
Is it possible to change that value, or is it set by httpd/WSGI?
You should never rely on the current working directory being a specific location in web applications because what it will be will be different for different hosting mechanisms. So, don't even try to change the current working directory as it will only lead to grief eventually by then relying on that.
Instead you should organise your code to use an absolute path. This would need to be either hard coded, be added as a suffix to some prefix from configuration, or calculated on the fly relative to the location of the code file being executed. In the latter you would do:
import os
here = os.path.dirname(__file__)
path = os.path.join(here, 'relative/path/file.txt')
I'm trying to generate some LaTeX code which from thereon should generate PDF documents.
Currently, I'm using the Django templating system for dynamically creating the code, but I have no idea on as how to move on from here. I understand that I could save the code in a .tex file, and use subprocess to run pdflatex for generating the PDF. But I had so much trouble escaping the LaTeX code in "plain" Python that I decided to use the Django templating system. Is there a way that I could somehow maybe pipe the output produced by Django to pdflatex? The code produced is working properly, it's just that I do not know what to do with it.
Thanks in advance
I was tackling the same issue in a project I had previously worked on, and instead of piping the output, I created temporary files in a temporary folder, since I was worried about handling the intermediate files LaTeX produces. This is the code I used (note that it's a few years old, from when I was still new to Python/Django; I'm sure I could come up with something better if I was writing this today, but this definitely worked for me):
import os
from subprocess import call
from tempfile import mkdtemp, mkstemp
from django.template.loader import render_to_string
# In a temporary folder, make a temporary file
tmp_folder = mkdtemp()
os.chdir(tmp_folder)
texfile, texfilename = mkstemp(dir=tmp_folder)
# Pass the TeX template through Django templating engine and into the temp file
os.write(texfile, render_to_string('tex/base.tex', {'var': 'whatever'}))
os.close(texfile)
# Compile the TeX file with PDFLaTeX
call(['pdflatex', texfilename])
# Move resulting PDF to a more permanent location
os.rename(texfilename + '.pdf', dest_folder)
# Remove intermediate files
os.remove(texfilename)
os.remove(texfilename + '.aux')
os.remove(texfilename + '.log')
os.rmdir(tmp_folder)
return os.path.join(dest_folder, texfilename + '.pdf')
The dest_folder variable is usually set to somewhere in the media directory, so that the PDF can then be served statically. The value returned is the path to the file on disk. The logic of what its URL would be is handled by whatever function sets the dest_folder.