在python中如何设置当前工作目录

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

在python中如何设置当前工作目录

A.TNG
Hi All,
 
python中可以使用 os.getcwd()获取当前工作目录,有没有方法来设置当前工组目录呢?
 
多谢.

--
Best Regard,
Tang, Jiyu (Joey)

_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 在python中如何设置当前工作目录

大郎
当前文件目录已经在可搜索的目录中了,要将其他目录加进来使用
import sys
sys.path.append('app/models')
 
你说的当前工组目录是指什么?

 
On 1/20/08, Joey <[hidden email]> wrote:
Hi All,
 
python中可以使用 os.getcwd()获取当前工作目录,有没有方法来设置当前工组目录呢?
 
多谢.

--
Best Regard,
Tang, Jiyu (Joey)

_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://python.cn/mailman/listinfo/python-chinese" target="_blank"> http://python.cn/mailman/listinfo/python-chinese



--
http://del.icio.us/iexper
http://twitter.com/qichangxing
http://webpy.org
http://blog.hi0791.com (build with web.py)
http://www.baicai.com 百才招聘
Gtalk: iexper(at)gmail.com


_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 在python中如何设置当前工作目录

HG-11
In reply to this post by A.TNG
chdir()

On 1/20/08, Joey <[hidden email]> wrote:

> Hi All,
>
> python中可以使用 os.getcwd()获取当前工作目录,有没有方法来设置当前工组目录呢?
>
> 多谢.
>
> --
> Best Regard,
> Tang, Jiyu (Joey)
> _______________________________________________
> python-chinese
> Post: send [hidden email]
> Subscribe: send subscribe to
> [hidden email]
> Unsubscribe: send unsubscribe to
> [hidden email]
> Detail Info:
> http://python.cn/mailman/listinfo/python-chinese
>


--
关注LAMP平台、安全、及web开发的个人blog: http://hackgou.itbbq.com
PGP KeyID: hackgou#Gmail.com
PGP KeyServ: subkeys.pgp.net
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Django ORM问题

Handle Huang
在Django中如果用 "python manage.py sqlall urus" 命令创建数据库脚本,但是没有效果,是否这个命令对目录结构有特殊要求,因为这里我修改了默认的结构,如果在不修改结构的情况下,要如果做?


urus
│  urls.py
│  urls.pyc
│  __init__.py
│  __init__.pyc

├─models
│      projects.py
│      __init__.py
│      __init__.pyc

└─views
        main.py
        main.pyc
        __init__.py
        __init__.pyc_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 在python中如何设置当前工作目录

A.TNG
In reply to this post by HG-11
恩,搞定了
就是使用的 os.chdir()
 
非常感谢


 
2008/1/20 憨狗 <[hidden email]>:
chdir()

On 1/20/08, Joey <[hidden email]> wrote:
> Hi All,
>
> python中可以使用 os.getcwd()获取当前工作目录,有没有方法来设置当前工组目录呢?
>
> 多谢.
>
> --
> Best Regard,
> Tang, Jiyu (Joey)
> _______________________________________________
> python-chinese
> Post: send [hidden email]
> Subscribe: send subscribe to
> [hidden email]
> Unsubscribe: send unsubscribe to
> [hidden email]
> Detail Info:
> http://python.cn/mailman/listinfo/python-chinese
>


--
关注LAMP平台、安全、及web开发的个人blog: http://hackgou.itbbq.com
PGP KeyID: hackgou#Gmail.com
PGP KeyServ: subkeys.pgp.net
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese



--
Best Regard,
Tang, Jiyu (Joey)
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: Django ORM问题

book4e
In reply to this post by Handle Huang
sqlall 只是显示 sql 语句,并不 sync 到数据库吧。

_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

答复: Django ORM问题

Handle Huang

是对,我现在只是希望他先是sql,但是他没有显示,不知道什么原因,网上我也没查到

 

发件人: [hidden email] [mailto:[hidden email]] 代表 book4e
发送时间: 2008120 22:22
收件人: [hidden email]
主题: Re: [python-chinese] Django ORM问题

 

sqlall 只是显示 sql 语句,并不 sync 到数据库吧。


_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: Django ORM问题

cougar cougar
In reply to this post by Handle Huang
还是跟结构有关系吧,应该按照正常的走吧,要不找不到你的模型定义的地方,所以没有执行结果吧
 
你 manage.py startapp xxx  试试,改下面的模型
 

cougar2008
2008-01-20

发件人: Handle.Huang
发送时间: 2008-01-20 21:31:01
收件人: [hidden email]
抄送:
主题: [python-chinese]Django ORM问题
 
在Django中如果用 "python manage.py sqlall urus" 命令创建数据库脚本,但是没有效果,是否这个命令对目录结构有特殊要求,因为这里我修改了默认的结构,如果在不修改结构的情况下,要如果做?
 
 
urus
│  urls.py
│  urls.pyc
│  __init__.py
│  __init__.pyc
├─models
│      projects.py
│      __init__.py
│      __init__.pyc
└─views
        main.py
        main.pyc
        __init__.py
        __init__.pyc_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]

_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

答复: Django ORM问题

Handle Huang

如果使用默认的模型的话,那一个app就只有一个model.py,如果这个app有很多表的话,难道所有的表都要定义在这个一个文件中,要是再加上自定义方法,这个文件将会是很恐怖的,而且结构上也不好啊。

 

PS

         这个app已经在setting.py中已经定义了

 

发件人: [hidden email] [mailto:[hidden email]] 代表 cougar2008
发送时间: 2008120 22:38
收件人: [hidden email]
主题: Re: [python-chinese] Django ORM问题

 

还是跟结构有关系吧,应该按照正常的走吧,要不找不到你的模型定义的地方,所以没有执行结果吧

 

manage.py startapp xxx  试试,改下面的模型

 


cougar2008

2008-01-20


发件人: Handle.Huang

发送时间: 2008-01-20 21:31:01

收件人: [hidden email]

抄送:

主题: [python-chinese]Django ORM问题

 

Django中如果用 "python manage.py sqlall urus" 命令创建数据库脚本,但是没有效果,是否这个命令对目录结构有特殊要求,因为这里我修改了默认的结构,如果在不修改结构的情况下,要如果做?

 

 

urus

│  urls.py

│  urls.pyc

│  __init__.py

│  __init__.pyc

─models

│      projects.py

│      __init__.py

│      __init__.pyc

└─views

        main.py

        main.pyc

        __init__.py

        __init__.pyc_______________________________________________

python-chinese

Post: send [hidden email]

Subscribe: send subscribe to [hidden email]

Unsubscribe: send unsubscribe to  [hidden email]

_______________________________________________

python-chinese

Post: send [hidden email]

Subscribe: send subscribe to [hidden email]

Unsubscribe: send unsubscribe to  [hidden email]


_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
vcc
Reply | Threaded
Open this post in threaded view
|

Re: 答复: Django ORM问题

vcc
你用多少个文件定义模型都可以,但是你一定要在你的app目录下有一个models.py,因为django只会load这个文件,然后在models.py里import其他文件里的模型,例如:
import models_1
import models_2
...
这样就可以工作了。
 
----- Original Message -----
Sent: Sunday, January 20, 2008 10:46 PM
Subject: [python-chinese] 答复: Django ORM问题

如果使用默认的模型的话,那一个app就只有一个model.py,如果这个app有很多表的话,难道所有的表都要定义在这个一个文件中,要是再加上自定义方法,这个文件将会是很恐怖的,而且结构上也不好啊。

 

PS

         这个app已经在setting.py中已经定义了

 


_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

答复: 答复: Django ORM问题

Handle Huang

好的,谢谢

 

发件人: [hidden email] [mailto:[hidden email]] 代表 vcc
发送时间: 2008120 23:15
收件人: [hidden email]
主题: Re: [python-chinese] 答复: Django ORM问题

 

你用多少个文件定义模型都可以,但是你一定要在你的app目录下有一个models.py,因为django只会load这个文件,然后在models.pyimport其他文件里的模型,例如:

import models_1

import models_2

...

这样就可以工作了。

 

----- Original Message -----

Sent: Sunday, January 20, 2008 10:46 PM

Subject: [python-chinese] 答复: Django ORM问题

 

如果使用默认的模型的话,那一个app就只有一个model.py,如果这个app有很多表的话,难道所有的表都要定义在这个一个文件中,要是再加上自定义方法,这个文件将会是很恐怖的,而且结构上也不好啊。

 

PS

         这个app已经在setting.py中已经定义了

 


_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: Django ORM问题

yi huang-3
In reply to this post by Handle Huang
from urus.models import YourModel
你只需要在 models 包的 __init__.py 导入projects.py 里面的 Model 名字即可。

 
On 1/20/08, Handle.Huang <[hidden email]> wrote:
在Django中如果用 "python manage.py sqlall urus" 命令创建数据库脚本,但是没有效果,是否这个命令对目录结构有特殊要求,因为这里我修改了默认的结构,如果在不修改结构的情况下,要如果做?


urus
│  urls.py
│  urls.pyc
│  __init__.py
│  __init__.pyc

├─models
│      projects.py
│      __init__.py
│      __init__.pyc

└─views
       main.py
       main.pyc
       __init__.py
       __init__.pyc_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese



--
http://codeplayer.blogspot.com/
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

求助:Django ORM问题

Handle Huang
In reply to this post by vcc

还是无法生成别的文件中的表,除了models.py的表被生成外,外部文件的表没有生成

 

 

文档结构如下:

G:.

  manage.py

  settings.py

  settings.pyc

  urls.py

  urls.pyc

  __init__.py

  __init__.pyc

└─urus

     models.py

     models.pyc

     views.py

     __init__.py

     __init__.pyc

  

   └─db

           log.py

           log.pyc

           __init__.py

           __init__.pyc

 

 

以下是models.py

 

from django.db import models

from urus.db.log import log

# Create your models here.

class projects(models.Model):

    name=models.CharField(maxlength=255,unique=True)

owner=models.CharField(maxlength=255,null=True)

 

 

urus/db/log.py

 

from django.db import models

 

class log(models.Model):

comments=models.CharField(maxlength=1000)

 

 

 

发件人: [hidden email] [mailto:[hidden email]] 代表 vcc
发送时间: 2008120 23:15
收件人: [hidden email]
主题: Re: [python-chinese] 答复: Django ORM问题

 

你用多少个文件定义模型都可以,但是你一定要在你的app目录下有一个models.py,因为django只会load这个文件,然后在models.pyimport其他文件里的模型,例如:

import models_1

import models_2

...

这样就可以工作了。

 

----- Original Message -----

Sent: Sunday, January 20, 2008 10:46 PM

Subject: [python-chinese] 答复: Django ORM问题

 

如果使用默认的模型的话,那一个app就只有一个model.py,如果这个app有很多表的话,难道所有的表都要定义在这个一个文件中,要是再加上自定义方法,这个文件将会是很恐怖的,而且结构上也不好啊。

 

PS

         这个app已经在setting.py中已经定义了

 


_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese