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 4 years ago.
Improve this question
I have downloaded some sample tpl files from the internet, i wanted to customise menu on my site thus i was trying to create new base.tpl file. However when I have saved it bottle does not want to read it and and return that:
bottle.TemplateError: Template 'base.tpl' not found.
Strange thing is that one is percived as rtf file and the other one (base.tpl downloaded from the internet) as the exec file. Why is that and how to fix this? Screenshot bellow:
I am referring to them with:
return template('base'). My educated guess is that it is textedit problem (I am using macOS) as it is trying to interpret the file and does not show the real html/tpl content.
Templates are regular bottle tpl files, nothing extraordinary they are saved in my project directory.
As to the directory list
However what I did is downloaded a different text editor then TextEdit and opened it in both in TextEdit you have:
Whereas in Atom text editor it looks like this:
Nevertheless files that were not created in TextEdit work perfectly fine.
Problem was with how the TextEdit perceived .tpl files changing text editor has helped files created via any other editor than TextEdit were interpreted correctly.
Related
I'm currently working on this project: https://github.com/lucasmolinari/unlocker-EX.
It's a excel unlocker, it works by editing the XML files inside the workbooks. (more information on the github page).
The script works fine in workbooks with almost no content inside, but recently I'm testing some bigger workbooks, and when I open the unlocked file, excel says it's corrupted and I can't find any difference between the original and the unlocked workbook, I'm 100% sure the problem is when the script change the content in the file, I watched every step of the script and it just stops working when the files are edited.
Does someone have more knowlege on how XML files work or in the structure of excel workbooks? Or like, some way to verify the differences between the original file and the edited to see if is some formatting problem..? I'm really sorry about this question, but I have no idea from where to start now, I tried everything I can.
Changed to open files in UTF-8 format and tried to find any corrupted character in the edited file,but manually is too hard to find any.
Using ElementTree library solves the problem
This question already has answers here:
Python: Get a list of selected files in Explorer (WIndows 7)
(4 answers)
Closed 8 months ago.
My problem is that I am making a program that will get file's data as per the folder that the user has opened as a file explorer... and I have surfed the whole internet to find the answer but it seems that this problem is never faced by anybody before. Many answers are related to the current working directory in which project files are situated.
So, I basically want the path for the folder which is currently being viewed by the user in file explorer...
Best way I can imagine doing that is write your Python software to use context menu in Explorer. With quick googling I found a interesting library for that: https://pypi.org/project/context-menu/
I suppose that there is no sensible way to read data from another process. That would cause security problems.
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 3 years ago.
Improve this question
there
I'm trying to make a Robotic Process Automation(called RPA) using python.
There are two windows; one is excel and the other is web.
The Procedure is:
Both excel and web must be opened before run the code(It never be changed, there are no alternatives)
the data on the web is copied and pasted to excel file.
done!
It looks easy... but, selenium cannot access to already opened web and cannot access to already opened excel file.
of course, it could be easy to access to new web and new or load excel.
It doesn't matter selenium and are not used.
Does somebody know how to solve it??
Thank you.
I see what you are trying to do, but there are easier ways to do this. Some questions to consider:
1. Is selenium the right tool for the job?
Do you need to simulate an entire browser navigate and download the file, or can you use some code to more simply download the file? Simulating the browser seems like a good idea until you notice you can simply scrape the website.
Using something like requests to download a webpage and something like BeautifulSoup to extract the specific link for the .xlsx, you can perhaps more easily achieve what you are looking for.
If selenium is indeed needed you should look into how to download the file -- not copy and paste it into Excel. Copying the file from the browser will require you to figure out some things like how to paste it on Excel, and extract individual HTML tags... which I bet will be inconceivably hard.
2. Do you wish to modify the.xlsx file?
If not, you should simply download it to a specific directory in your computer, and open the file on Excel with Python. If yes, then you will have to look into tools like pandas.
Don't give up.
If you looking to get this project to work you gotta keep in mind that programming is 65%-70% research and 25%-30% actually programming. The above resources should get you started, but it is vague enough that you will have to do your own research to get it going.
As per my knowledge, selenium will only interact with those windows, that are invoked by it, but not on those which were already open. But, here are some related threads said we could do it using remote WebDriver and Session ID, you could check them:
How can I reconnect to the browser opened by webdriver with selenium?
Re-using existing browser session in selenium
Can Selenium interact with an existing browser session?
From my point of view, if you want to access the already opened IE window and Excel Worksheet, I suggest you could try to use VBA.
More detail information, please check the following articles:
Understanding automation
Excel + VBA + IE = web automation
How do I set the value to an already open Excel workbook?
How to navigate to an already opened internet explorer window? (VBA)
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 6 years ago.
Improve this question
I have been looking at some python modules and powershell capabilities to try and import some data a database recently kicked out in the form of folders and text files.
File Structure:
Top Level Folder > FOLDER (Device hostname) > Text File (also contains the hostname of device) (with data I need in a single cell in Excel)
The end result I am trying to accomplish is have the first cell be the FOLDER (device name) and the second column contain the text of the text file within that folder.
I found some python modules but they all focus on pulling directly from a text doc...I want to have the script or powershell function iterate through each folder and pull both the folder name and text out.
This is definitely do-able in Powershell. If I understand your question correctly, you're going to want to use Get Child-Itemand Get Content then -recurse if necessary. As far as an export you're going to want to use Out-File which can be a hassle when exporting directly to xlsx. If you had some code to work with I could help better but until then this should get you started in the right direction. I would read up on the Getcommands because Powershell is very simple to write but powerful.
Well, Since you're asking in a general sense -- you can do this project simply in either choice of script languages. If it were me -- and I had to do this job once -- I'd probably just bang out a PoSH script to do it. If this script had to be run repeatedly, and potentially end up with more complex functions I'd probably then switch to Python (but that's just based on my personal preference as PoSH is pretty powerful in a Windows env). Really this seems like a 15 line recursive function in either choice.
You can look up "recursive function in powershell" and the same for python and get plenty of code examples, as File Tree Walks (FTW :) ) are one of the most solved problems on sites like this. You'd just replace whatever the other person is doing in their walk with a read of the file and write. You probably also want to output in CSV format because it's easier and imports into excell just fine.
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 am very new to programming world. I have started learning Python. I am trying to develop a program that gets user input, runs some commands in the background and then display the output on web interface. Although it is little more complex, but for simplicity, you can consider this as:
user enters a filename
python code runs "cat filename"
output is displayed on the screen.
I have Python + Django + Apache setup. I am using HTML to to display the output. It is working fine as long as the output being returned is reasonably small. But sometimes I have huge output (~700 MB) and obviously I am having difficulty displaying it on web interface.
Code Snippet:
op = subprocess.check_output(cmd,universal_newlines=True)
return render (request, 'display.html', {'op': op})
What is the best approach to display such large content on web? Some points I wanted to put on the table:
Store the output in a file rather than a string. Read the file in chunks.In this case, can I have my code write to the file and read the file for display simultaneously? I don't think it is a good idea but wanted to check.
Are there any python packages intended to resolve such problem? Any django feature?
When I have huge output, it takes a while for the program to get the output and then it takes a while to be displayed on the screen.
You can't display 700 MB of alphanumerical data at once on any regular screen and even if you could, a user would drown in it. So you should display portions and enable scrolling or selection. As you indicate, loading all this data costs quite some time. But since you don't view it in one piece, you also don't have to load it in one piece. Rather than refreshing your whole page you should use Ajax (as e.g. implemented in jQuery) to have the browser load your data into an appropriate HTML/DOM element in portions as indicated by the user who e.g. shifts a scrollbar. Given the fact that 700 MB even in that case is just too much, a better way would be to select data for display using some type of hierarchical (tree) control or another non-sequential selection mechanism. The only task of Django in this case, apart from serving the page itself, is serving the requested data portion, e.g. as JSON data. As mentioned the page holding both the displayed data portion and the selection controls is served only once.
Take a look at some of the jQuery Infinite Scrolling options here.