python将脚本复制到脚本中 [英] python copy scripts into script

查看:222
本文介绍了python将脚本复制到脚本中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第1部分:复制脚本

我在我的电脑上有我想继续开发的脚本。这些脚本在maya文件中用作嵌入脚本,因此打开文件的人员在打开该文件时将获得该工具。我想建立一个更新功能,所以,当我打开文件,该文件中的版本将检查我的本地版本,如果我的本地版本是一个更高的版本号,它将更新到我的脚本。我知道如何替换字符串值在maya,但我不知道如何从现有的python文件中复制字符串值。

I have scripts on my computer that I want to continue to develop. These scripts work as embed scripts in maya files, so that people who open the file will get the tool upon opening it. I want to build in an update function, so that when I open the file, the version in the file will check against my local version, and if my local version is a higher version number, it will update to my script. I know how to replace the string value in maya, but i'm not certain how to copy the string value from an existing python file.

如何复制文本从脚本内的字符串值? (最好包含/ n和缩进,而我在它)

How can I copy the text from within a script to a string value? (preferably containing /n and indentation, while I'm at it)

version = 3.1
Try:
    import ToolBox
    if ToolBox.version > version:
        #do copy stuff

第2部分:多个脚本文件

Part 2: Multiple Script Files

我的脚本使用几个单独的文件(简化的概念)

My script uses several separate files (simplified concept bellow)

file Hammer
    class Type():
        #force stuff
    def strike():
        #strike stuff
file Nail
    Class Type():
        #Type stuff
    def bindTogether():
        #bind stuff
file Wood
    #wood stuff..

file ToolBox
    Import Hammer
    Import Nail
    Import Wood
    def buildBox():
        #buildBox stuff using hammer, nail and wood

我可以将这些导入到我的脚本中的类中,并使用它们几乎和我现在一样吗?

Can I import these into a class within my script and use them pretty much the same as I am now? If not, what can I do?

File Toolbox
    Class Hammer:
        class Type():
            #force stuff
        def strike():
            #strike stuff
    Class Nail:
        Class Type():
            #Type stuff
        def bindTogether():
            #bind stuff
    Class Wood:
        #wood stuff

    def buildBox():
        #buildBox stuff using hammer, nail and wood


推荐答案

我想你想重新考虑提出。分散事情片刻的是要求麻烦:如果你的用户得到不同的代码,根据你的机器上发生了什么,以及他们做事情的顺序,你可以在不同的机器上得到很多很多不同的状态,所以每个用户可以得到自己独特的bug集。您希望分发工具并将工具下载为一个单元,以便用户一次可以获得一套完整的工具,而不是一次一个。

I think you want to reconsider the approach you're proposing. Distributing things piecemeal is asking for trouble: if your users get different code depending on what's going on on your machine and also on the order in which they do things, you can potentially get lots and lots of different states on different machines so each user can get their own unique set of bugs. You want to distribute the tools and download the tools as a unit so the user gets a complete suite of tools at a time, not one at a time.

最简单的方法为您的用户提供指向网络共享的环境变量。您的userSetup.py可以使用它来将整个共享的内容复制到用户启动时的用户;这样用户得到的一切的相同版本。你需要小心地删除任何现有的.pyc文件作为过程的一部分,因为剩下的pyc可以愚弄python使用错误的代码。

The simplest way to do give your users an environment variable that points to a network share. Your userSetup.py can use that to copy the contents of the whole share to the users when they start up; that way the users get the same versions of everything. You need to be careful to delete any existing .pyc files as part of the process, since leftover pycs can fool python into using the wrong code.

另一个选择是考虑使用Maya模块文件。一旦你给每个用户一个指向你的网络共享的模块文件,每个人都可以直接从网络共享工作。它不能为数百个用户扩展好,但十几个工作正常:请参阅 http://techartsurvival.blogspot.com/2014/01/mayas-mildy-magical-modules.html

Another option to consider is using Maya module files. Once you give every user a module file that points at your network share everybody can work directly off a network share. It doesn't scale well for hundreds of users but for a dozen or so it works fine: see http://techartsurvival.blogspot.com/2014/01/mayas-mildy-magical-modules.html

如果您想要了解一些涉及的问题try:

If you want to read up on some of the issues involved try:

  • http://tech-artists.org/forum/showthread.php?3271-Distribution-techniques-for-external-Python-tools&highlight=distribution
  • http://tech-artists.org/forum/showthread.php?3187-Wrapping-DCC-Tools-to-start-them-in-different-quot-environments-quot&highlight=distribution
  • http://techartsurvival.blogspot.com/2014/06/save-environment.html?q=environment
  • http://techartsurvival.blogspot.com/2014/07/save-environment-2-i-am-egg-man.html?q=environment

这篇关于python将脚本复制到脚本中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆