Skip to main content
Question

Qapp - Input Variable File - How to Open File in Python from Netbrain Desktop

  • August 27, 2025
  • 1 reply
  • 21 views

Greetings,

 

I am trying to open a text file named “simple-textfile’ on my NetBrain Desktop in a Python Script Module inside a Qapp but am receiving the following error message:

OSError: [Errno 22] Invalid Argument: ‘nbfile://Desktop/simple-textfile’

 

How can I get Python to read or interpret the filepath and open it for parsing?

 

Snippet Python Script:

jfile = $Input1.jfile 

with open(jfile, ‘r’) as f:

  asdf = f.read()

  AddMessage(asdf)

 

$Input1.jfile  is “nbfile://Desktop/sample-textfile”

 

I tested the filepath with os and it returns that the filepath does not exist:

import os

if os.path.exists(jfile):

  AddMessage(“The file path exists”)

else:

  AddMessage(“the file path does not exist”)

 

Result:

“The file path does not exist.”

 

Any help is greatly appreciated!

 

Best Regards,

 

Dave

1 reply

  • New Participant
  • 4 replies
  • November 6, 2025

Hi ​@dawal1337 
We cannot directly use Python file open function in netbrain Qapp as it requires absolute file path of file.

You need to import datamodel and use ReadNBFile to read the content of the file. In case of text file we should not give any extension while for CSV we can give .csv

Kindly use the below code:
 

from netbrain.sysapi import datamodel

#jfile = "nbfile://Public/Ajay/test"
jfile = "nbfile://Desktop/test"

csvfile = datamodel.ReadNBFile(jfile)
AddMessage(str(csvfile),2)
 

It works, I tested it. Thanks.