6

When writing code using PyQt or PySide, sometimes the equivalent function is available in both Qt and Python (e.g., QDir.exists in Qt vs os.path.exists in Python). In these cases, is there an established practice for which language to use?

I am wondering if issues of speed, refactoring, etc. might be relevant to the decision.

Thanks.

LozzerJP
  • 856
  • 1
  • 8
  • 23

1 Answers1

3

As I understand, many of those Qt functions were put in for cross-platform compatibility, and others to integrate with Qt. However, Python already includes cross-platform functions, so I would favor Python ones when possible since they're

  • More familiar to Python programmers
  • Doesn't make you so dependent on Qt
  • Fits in with Python's idioms

However, you may have to use Qt's functions since they integrate with Qt and/or they provide functionality that Python doesn't.

This has been discussed for other languages, e.g. C++: Qt: Qt classes vs. standard C++

Really, it depends on whether you want to write a Qt application or a Python application.

Community
  • 1
  • 1
li.davidm
  • 11,736
  • 4
  • 29
  • 31
  • 4
    Though there are situations where there is equivalent functionality in the standard python libs, but the PyQt versions wrap them up into the event loop with signals, such as QProcess, QThread... Python has them as well but they are Qt specialized. – jdi Jul 18 '12 at 16:03