Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7615983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:46:40+00:00 2026-05-31T02:46:40+00:00

I’m trying to create a very simple stand-alone app that converts CATIA .dat files

  • 0

I’m trying to create a very simple stand-alone app that converts CATIA .dat files into csv for ProCast.

I have a Qtwidget File dialog to get the .dat file :

app = QtGui.QApplication(sys.argv)
widget = QtGui.QWidget()
widget.show()
DATFILE = QtGui.QFileDialog.getOpenFileName(widget, 'Open File', '.')
NODES, ELEMENTS, CONNECT = read(DATFILE)

To load the data from the .dat file I first use with open(file) and a while loop and then np.genfromtxt for the rest of the file like so :

def read(infile):
    with open(infile, 'r') as inf:
        line = inf.readline()
        while "NODES" not in line:
            line = inf.readline()
        inf.readline()
        line = inf.readline()
        list_nodes = []
        while '$' not in line:
            x, y = line.split()[2:4]
            z = inf.readline().split()[2]
            list_nodes.append([float(x), float(y), float(z)])
            line = inf.readline()
    num_nodes = len(list_nodes)
    nodes = np.zeros((num_nodes, 4))
    nodes[:, 0] = np.arange(1, num_nodes+1)
    for n in range(len(list_nodes)):
        nodes[n, 1:] = np.fromiter(list_nodes[n], dtype=float)
skipheader = np.size(nodes, axis=0)*2+12
elements = np.genfromtxt(infile, dtype=int, comments='$', skip_footer=1,
                         skip_header=skiph, usecols=(3,4,5))

When I run the my read function with a infile argument as a string I type, it works perfectly, but when I try to use the filepath that PyQt File dialog gave me, numpy.genfromtxt fails :

Traceback (most recent call last):
File "E:\Felix\PJE\BOLOS\bolos.py", line 62, in <module>
NODES, ELEMENTS, CONNECT = lire(DATFILE)
File "E:\Felix\PJE\BOLOS\bolos.py", line 36, in lire
skip_header=skiph, usecols=(3,4,5))
File "C:\Python27\lib\site-packages\numpy\lib\npyio.py", line 1265, in genfromtxt
fhd.next()
StopIteration

from what I read in npyio.py the error occurs when it skips the lines I specified with skip_header, but I have no idea why it would fail now and not when I input the filename manually, since the other part of the read function works OK.

Also if it is a filename problem, wouldn’t the error be raised earlier ?
Can anyone see the (probably stupid and gross) mistake I made ?

I’m running python 2.7, Numpy 1.6.1 on windows 7.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:46:42+00:00Added an answer on May 31, 2026 at 2:46 am

    QFileDialog.getOpenFileName() returns a QString that you’re passing to your function. If it works fine when you pass the path as a string you type I’m guessing it’s a Python string that you’re entering?

    Try converting the QString to a Python string and see if that fixes things.

    DATFILE = str(QtGui.QFileDialog.getOpenFileName(widget, 'Open File', '.'))

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.