简体   繁体   English

Python和不同的操作系统

[英]Python and different Operating Systems

I am about to start a personal project using python and I will be using it on both Linux(Fedora) and Windows(Vista), Although I might as well make it work on a mac while im at it. 我即将开始使用python的个人项目,我将在Linux(Fedora)和Windows(Vista)上使用它,虽然我不妨在它上面使用它。 I have found an API for the GUI that will work on all 3. The reason I am asking is because I have always heard of small differences that are easily avoided if you know about them before starting. 我找到了一个适用于所有3的GUI的API。我问的原因是因为我总是听说如果你在开始之前了解它们就很容易避免的小差异。 Does anyone have any tips or suggestions that fall along these lines? 有没有人有这些方面的任何提示或建议?

In general: 一般来说:

  • Be careful with paths. 小心路径。 Use os.path wherever possible. 尽可能使用os.path。
  • Don't assume that HOME points to the user's home/profile directory. 不要假设HOME指向用户的主页/配置文件目录。
  • Avoid using things like unix-domain sockets, fifos, and other POSIX-specific stuff. 避免使用unix-domain套接字,fifos和其他特定于POSIX的东西。

More specific stuff: 更具体的东西:

  • If you're using wxPython, note that there may be differences in things like which thread certain events are generated in. Don't assume that events are generated in a specific thread. 如果你正在使用wxPython,请注意在某些事件中可能存在差异,比如在哪个线程中生成某些事件。不要假设事件是在特定线程中生成的。 If you're calling a method which triggers a GUI-event, don't assume that event-handlers have completed by the time your method returns. 如果您正在调用触发GUI事件的方法,请不要假设事件处理程序在方法返回时已完成。 (And vice versa, of course.) (当然,反之亦然。)
  • There are always differences in how a GUI will appear. GUI的显示方式总是存在差异。 Layouts are not always implemented in the exact same way. 布局并不总是以完全相同的方式实现。

Some things I've noticed in my cross platform development in Python: 我在Python的跨平台开发中注意到的一些事情:

  • OSX doesn't have a tray, so application notifications usually happen right in the dock. OSX没有托盘,因此应用程序通知通常发生在Dock中。 So if you're building a background notification service you may need a small amount of platform-specific code. 因此,如果您正在构建后台通知服务,则可能需要少量特定于平台的代码。
  • os.startfile() apparently only works on Windows. os.startfile()显然只适用于Windows。 Either that or Python 2.5.1 on Leopard doesn't support it. 要么是Leopard上的Python 2.5.1也不支持它。
  • os.normpath() is something you might want to consider using too, just to keep your paths and volumes using the correct slash notation and volume names. os.normpath()是您可能也想要考虑使用的东西,只是为了使用正确的斜杠符号和卷名来保持路径和卷。
  • icons are dealt with in fundamentally different ways in Windows and OSX, be sure you provide icons at all the right sizes for both (16x16, 24x24, 32x32, 48x48, 64x64, 128x128 and 256x256) and be sure to read up on setting up icons with wx widgets. 图标在Windows和OSX中以完全不同的方式处理,请确保为两者(16x16,24x24,32x32,48x48,64x64,128x128和256x256)提供所有正确尺寸的图标,并确保阅读有关设置图标的信息使用wx小部件。
  1. You should take care of the Python version you are developing against. 您应该处理您正在开发的Python版本。 Especially, on a Mac, the default version of Python installed with the OS, is rather old (of course, newer versions can be installed) 特别是在Mac上,随操作系统安装的Python的默认版本相当陈旧(当然,可以安装更新的版本)

  2. Don't use the OS specific libraries 不要使用特定于操作系统的库

  3. Take special care of 'special' UI elements, like taskbar icons (windows), ... 特别注意'特殊'UI元素,如任务栏图标(窗口),...

  4. Use forward slashes when using paths, avoid C:/, /home/..., ... Use os.path to work with paths. 使用路径时使用正斜杠,避免C:/,/ home / ...,...使用os.path来处理路径。

Some filename problems: This.File and this.file are different files on Linux, but point to the same file on Windows. 一些文件名问题:This.File和this.file是Linux上的不同文件,但指向Windows上的同一文件。 Troublesome if you manage some file repository and access it from both platforms. 如果您管理一些文件存储库并从两个平台访问它,那就太麻烦了。 Less frequent related problem is that of names like NUL or LPT being files on Windows. 较不常见的相关问题是像NUL或LPT这样的名称是Windows上的文件。

Binary distribution code (if any) would likely use py2exe on Win, py2app on Mac and wouldn't be present on Linux. 二进制分发代码(如果有的话)可能会在Win上使用py2exe,在Mac上使用py2app并且不会出现在Linux上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 不同操作系统上的Python程序 - Python programs on different Operating Systems 不同操作系统中的VirtualEnv - VirtualEnv in different operating systems openpyxl 在不同操作系统中的行为不同 - openpyxl act differently in different Operating systems Python上的select模块的不同功能(例如select(),poll(),epoll())在哪些操作系统上可用? - On what operating systems are the different functions of the select module in Python, like select(), poll(), epoll() available? Python读写文件时,如何在不同的操作系统上获取相同的路径? - How to get the same path on different operating systems when reading and writing files in Python? 在Python中不同操作系统下不改变路径读取Excel文件 - Read an Excel file without changing path under different operating systems in Python 用于查询多个操作系统版本的python脚本 - python script for enquiring the version of multiple operating systems Python 3导入操作系统之间的行为差​​异 - Python 3 import behaviour differences between operating systems input() 函数在不同的操作系统上以不同的方式处理数据类型? - input() function handling data types differently across different Operating Systems? Matplotlib 图形的 Output 图像在不同操作系统中具有不同的大小 - Output images of Matplotlib figures have different sizes across operating systems
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM