Parsing failed: Unsupported file format 'py' - python

I’m trying to run some robot framework tests in eclipse. I have Python, PyDev, Robot Framework (and all other things which I need) already installed, but it comes always the same error message "Parsing failed: Unsupported file format 'py'". Does anyone know where the problem may lie? Thank you in advance!

You will get this exact error if you tell robot to run a file as if it was a test case (e.g. robot something.py). The solution is pretty simple: don't pass a .py file as an argument to robot.

can you tell what did you try until now ? i cant comment that's why i ll write my Comments here. I think it have something to do with filenames. Maybe you gave a filename to robot, and robot can't find that file.
Maybe it also means :
the file does not exist. For example, maybe you forgot to save the file
you misspelled the filename
you spelled the filename correct, the file exists, but it is in a different directory than the current working directory.
here is some Question that maybe will help you if you have the same Problem:
Run suite of suites using argumentfile option

Related

Can't write to file, even though I have permissions to do so In Python

As the tittle implies, i am having trouble writing to a certain file, even though I have permissions to do so. I'm not getting an error; It's like the lines of code are just being ignored. They're not doing anything.
f = open("C:/ProgramData/Microsoft/Windows/Start Menu/Programs/StartUp/startupfile.py", 'w')
f.write("Stuff I want to write")
f.close()
Can anyone help me? Again, there's no error message. The lines are just being flat-out ignored. And yes, I am running it with permissions through the console. Is the problem that it's in the windows directory? Or am I just missing something painfully obvious here?
EDIT:
Thanks for the help everyone, but it turns out that the problem was just Windows being incompetent. I found that the files appeared after a restart, which works anyway because I'm writing in the Startup folder.
I don't have enough reputation to make a simple comment, so don't interpret this as a solution to your problem, but did you try opening the file in the "wt" mode instead of only "w"? "w" mode opens the file in binary as seen here, so the issue could be that the program doesn't understand what you are trying to say because you want to edit it in the text mode. Again, I'm not sure if this is right and I'm a newbie myself, so don't interpret this as a solution, more like a commentary.

Python is not recognising txt file from outside code

import os, sys
inputFilename = 'X.txt'
if not os.path.exists(inputFilename):
print('The file %s does not exist. Quitting...' % (inputFilename))
sys.exit()
This code is only meant to run when the txt file X is not found. But for some reason it keeps running these lines, even though the file does exist in the right place. Any ideas what I'm doing wrong?
I've tried moving everything into a separate folder and renaming file, nothing seems to be working.
Make sure that the IDE you're using recognises the folder, otherwise it might not find the file even if it exists in the folder.
Fx if you're using vs code, click on the option "open folder" and add the folder as a working platform. Check how to for whichever IDE you're using.
On another note,
if you're only using files it might be better practice to use isfile() instead of exists()
exists() is for files and directories, whereas isfile() is for just files. For just directories you can use isdir()
Where is the text file located?
Where are you running the python code from?
The answers to 1. and 2. should both be the same. If not, there's your issue.
I think you might be able to pass in an absolute path instead of just 'X.txt' to inputFileName. This way the directory layout won't matter.
There doesn't seem to be anything inherently wrong with your code. I tested out it locally and it works.

How to open a Unix Executable File using Python?

Sorry if this might be an easy question, but I'm trying to open a Unix Executable File using Python, but it doesn't have any file extensions attached to it. The file name looks something like 'filename_bib'. I typed this and it worked:
hdulist = open('filename_bib')
But next when I typed in hdulist.info() or hdulist.shape(), it doesn't give me anything, so I checked all its attributes and tried print(type()) and hdulist.attribute? for each attribute, but I didn't really understand any of the explanations, so I actually tried typing all of them to see what they would give me, but at some point it started giving me errors which said:
ValueError: I/O operation on closed file
so I think this may have happened when I tried using hdulist.close() or hdulist.closed(), but I don't know (1) if it was a mistake for me to try any of the attributes, (2) if it somehow changed anything from my original file, and (3) how to fix it.
I was told that this file contains bytes and that I should somehow be able to show a picture from it using Python, but this is my first time handling Unix Executable Files, and I have absolutely no idea how to start. I've handled fits and pl files before, but this is my first time trying to open something like this. I've tried looking up a bunch of things online already, but I can't find any instructions whatsoever. Please help me out if you know anything about this. I will be very grateful for any help that you could give me.
This is what it shows when I open it in Sublime:
enter image description here
As the default file access mode in python is "read only". Technically, since you have not mentioned any access mode in your command
hdulist = open('filename_bib')
file should only be for reading and nothing should have happend to the opened file.
Question:
Have you tried running it in UNIX by,
./filename_bib
What was the output?

IO error for saunter.ini while setting up py.Saunter

While setting up py.saunter on my system, I am getting an IO error for saunter.ini file.
Directory structure is exactly as shown in the example - https://github.com/Element-34/Py.Saunter-Examples
Below is the error message -
IOError: [Errno 2] No such file or directory: '/src/conf/saunter.ini'
ERROR: Module: Tests could not be imported
(file:/Users/.../PythonWorkspace/PySaunter/src/scripts/Tests.py)
I know there are lot of import related questions. Most of them suggest to add init.py if not already there. I have added init.py in every folder.
The code snippet which reads saunter.ini is as below -
def configure(self, config = "saunter.ini"):
self.config = ConfigParser.SafeConfigParser()
self.config.readfp(open(os.path.join("conf", config)))
Any help would be appreciated...
There isn't really enough here to diagnose the problem. But, in the examples directory there is actually two different projects (ebay and sauce) -- you have to be in one of them, not the top.
Also, Py.Saunter won't create saunter.ini for you. You need to create it (most easily by renaming saunter.ini.default).
Oh, and don't try and run it from checkout from Github -- it really does need to be from an egg. If there are bits missing from http://element34.ca/products/saunter/pysaunter which prevent you from getting started, let me know and I'll modify the page.
(Now if only I remembered by SO credentials...)
I was running the project from eclipse as a unit-test which is why it was throwing import errors.
Py.Saunter is an opinionated framework and does not support eclipse or any other IDE at this point.
It works fine when executed from the command line as illustrated in the site - http://element34.ca/products/saunter/pysaunter
Should ensure to execute from the home directory.

python saving unicode into file

i'm having some trouble figuring out how to save unicode into a file in python. I have the following code, and if i run it in a script test.py, it should create a new file called priceinfo.txt, and write what's in price_info to the file. But i do not see the file, can anyone enlighten me on what could be the problem?
Thanks a lot!
price_info = u'it costs \u20ac 5'
f = codecs.open('priceinfo.txt','wb','utf-8')
f.write(price_info)
f.close()
I can think of several reasons:
the file gets created, but in a different directory. Be certain what the working
directory of the script is.
you don't have permission to create the file, in the directory where you want to create it.
you have some error in your Python script, and it does not get executed at all.
To find out which one it is, run the script in a command window, and check for any error output that you get.
Assuming no error messages from the program (which would be the result of forgetting to import the codecs module), are you sure you're looking in the right place? That code writes priceinfo.txt in the current working directory (IOW are you sure that you're looking inside the working directory?)

Categories

Resources