This question may sounds dumb, but I can't manage to find a correct answer on my own.
I am trying to use the SVG DOM interface in my python script. I would like to use getComputedTextLength but I can't find how even if I firstly thought it would be available thanks to modules or a packages like python-svg or something like that.
I am sure there is something I miss, but I can't find what.
Any help would be appreciated.
Thank you.
EDIT: I forgot to talk about what my script actually does. It's a Python script used to generate a SVG file from data grabbed on the Internet. My script needs to write texts and repeat them all along a path. Also, as I know the exact length (in pixels) of the path I need to know the length of the text in order to repeat it only what I need to. That's why a method like getComputedTextLength would be helpful.
Try this: http://www.gnu.org/software/pythonwebkit/
I don't think this is possible. DOM is one thing and calling browser's function is other thing. I only saw Python module which help you to create tree structures like HTML or SVG but they don't provide any other additional functionality. (Btw., last time I look even browsers had problems correctly computing getComputedTextLength but that was some time ago...)
You could try better luck with fonttools.
Related
I am trying to extract data from a .txt file which embodies certain measurement values that I would like to use inside Python. I am doing this with the numpy module (numpy.genfromtxt), which saves the values into an array.
Nevertheless, whenever there is a decimal value, it is written with a comma (1,456 f.e.), which Python does not accept as a decimal. Sadly, this is the way that the data has been given to me. Now, I would like to write a Python Code that goes through all elements of the array, basically looks out for commas and changes them to dots (I have multiple files and I would like to automate this process, even though I could technically do it manually :) ).
As I have started programming with C and C++, I would have done this with pointers and loops. Nevertheless, the pointer concept does not seem to exist in Python or is at least not advised. I would be very glad if any of you could please tell me whether there is a way to advance this problem in Python. Thank you very much!
Welcome to SO. Please give more details. We cannot answer you if you do not include the code you wrote yet / sample data / and full error messages
about your trial to solve this problem, so we can reproduce and help.
See MRE here: https://stackoverflow.com/help/minimal-reproducible-example
read the file content and replace the "," characters like so:
with open('file.txt.','r') as f:
content = f.read().replace(',','.')
# do whatever with "content"
HI I am new managing excel files, I would like to know if there is any variable in xlutils, xlrd, xlm, etc libraries that give true or false in case Macros are activated or now? Is there any way to know it from metadata before open? Wat is the best approach for know it?
Thanks a lot in advance.
It's technically possible but very unlikely that Excel is calling any Python functions.
A quick Google Search shows lots of people asking if VBA can use Python, and a few theoretical responses, but nothing solid.
What I would do to confirm, is move all the "mystery python scripts" to another folder. If someone complains that things suddenly don't work any more, then move them back.
If a couple months pass and everything's still working properly, it's unlikely that anyone needs them.
Edit:
Figures... as I was writing that answer someone posted a VBA/Python question!
...but out of curiousity, I queried SE Data Explorer:
Questions with tags like %vba% or %excel%: 212,299
Questions with tags like %python% and (%vba% or %excel%): 5,808 (2.7%)
I want python to click Enter. However, I don't want to install any outside extensions. I want it to click enter without using them. I found many resources like win32 but I want to do it without using external resources. I don't mind which version of python it is on.
Is this possible?
If so, how?
I have looked on the web but couldn't find anything. Please, can someone help?
Thank you in advance.
Yes.
It should definitely be possible using the ctypes library to talk directly to the Windows dlls
If you don't want to install a helper module that has done all this for you, then you pretty much have to do it old school by going after the really low level code.
In short, call the SendInput function of user32.dll by using ctypes.windll.user32.SendInput. Good luck with getting the parameters correct - I don't have the patience to figure it out for you.
Here are the docs for the user32.dll SendInput API
Here is a helpful resource for figuring out the data types. This is actually part of ctypes and can be imported by import ctypes.wintypes but I find it instructional to read the actual code.
So for example, to create a WORD with the value of the Virtual Key Code VK_RETURN, I think it would be
>>> ctypes.wintypes.WORD(0x0D)
c_ushort(13)
But there is a lot more you have to piece together from there. Just build up your parameters and call the function.
Last hint, use the examples in the second link for how to build "C" type structures. Then build one yourself using ctypes.Structure
Is there a way to save the current Python session? I would like to be able to save all my Python variables, functions, and imported libraries. If possible, having the history saved would be nice. I have looked all over Google and Stackoverflow for a simple command to do this, but have found nothing quite fitting what I want. Some suggested downloading new software, which I don't want. Others had big scripts that they wrote to do this for them.
I'm looking for a no-nonsense easy to use command. Is there one? If not, how would you suggest to make one?
UPDATE: readline.write_history_file() and readline.read_history_file() save the history.
I think the closest thing you're going to find is ipython. I'm not sure if it does the variable saving thing, but I believe it does everything else you're asking for.
1.) After typing all commands just do CTRL+S.
2) Give a file name and say OK.
This works for Python Shell.
I have an executable (converted to exe from python using py2exe) that outputs lists of numbers that could be from 0-50K lines long or a little bit more.
While developing, I just saved them to a TXT file using simple f.write.
The person wants to print this output on paper! (don't ask why lol)
So, I'm wondering if I can output it to something like HTML? XML? Something that could display tables of 50K lines and maybe 3 columns and that would also run in any PC without additional programs?
Suggestions?
EDIT:
Regarding CSV:
In most situations the best way in my opinion would be to make a CSV. I'm not opposing it in anyway, rather I think others might find Lott's answer useful for their cases. Sorry I didn't explain it that well in my question as far as my constraints go.
My constraints are: the user doesn't have an office suite, no python installed. Just think of a PC that has the bare minimum after a clean windows xp/vista installation, maybe Internet Explorer 7 or 8. This PC has to be able to open my output file and allow for reasonable viewing, searching, and printing.
CSV.
http://docs.python.org/library/csv.html
http://en.wikipedia.org/wiki/Comma-separated_values
They can load a spreadsheet and print anything they want.
If you can't install anything on the computer, the you might be best off outputting an HTML file with the data in a <table> that the user could view/search/print in IE.
You could use LaTeX to produce a PDF, maybe? But why exactly isn't a text file good enough?
You can produce a PDF using Reportlab. After all if you really want full control of the printed output, there's nothing that beats PDF.
Does 50k lines make too large a file? If not, just continue writing text files. Otherwise an easy solution would be to continue spitting out text files and compress them, e.g. with zip. You could use the zipfile library in Python. Most computers have no trouble reading zip files.