包名中的关键字。 [英] keyword in package name.

查看:151
本文介绍了包名中的关键字。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Everyone,


我习惯在包名中反向使用域名(应用程序或

公司)。


例如com.spam.app1


我最近开始了一个印度域名项目(tld = .in),

导致一个包名喜欢


in.spam.app1


这导致语法错误,如in是一个关键字。

我明白这是一个不幸的功能,但有任何人

之前遇到过这个问题,

并且是有可能的解决方法。


PS这也是冰岛域的一个问题(tld = .is)。

TLD: http://data.iana.org/TLD/tlds-alpha-by-domain.txt

Python关键字: http://www.python.org/doc /2.5.2/ref/keywords.html


问候,

Abhishek Mishra

Hello Everyone,

I have the habit of using domain names (of either the application or
company) in reverse in package names.

for e.g. com.spam.app1

I''ve recently started a project for an indian domain (tld = .in),
which leads to a package name like

in.spam.app1

This causes a syntax error, as "in" is a keyword.
I understand that this is an unfortunate "feature", but has anyone
faced this problem before,
and is there a possible workaround.

P.S. this would also be a problem for the iceland domains (tld = .is).
TLDs: http://data.iana.org/TLD/tlds-alpha-by-domain.txt
Python Keywords: http://www.python.org/doc/2.5.2/ref/keywords.html

Regards,
Abhishek Mishra

推荐答案

10月19日,12:11 * pm,Tino Wildenhain< t ... @ wildenhain.dewrote:
On Oct 19, 12:11*pm, Tino Wildenhain <t...@wildenhain.dewrote:

Abhishek Mishra写道:
Abhishek Mishra wrote:

Hello Everyone,
Hello Everyone,


我有使用域名的习惯(应用程序或

公司)的包名称相反。
I have the habit of using domain names (of either the application or
company) in reverse in package names.


例如com.spam.app1
for e.g. com.spam.app1



虽然这对java来说似乎是一个好主意,但我认为它不会让你觉得对于python来说是有意义的 - 原因是:在python中你有一个导入

机制,在java中你只有命名空间。


因此你总是可以在导入时避免命名空间冲突。


While this seemed a good idea for java, I don''t think it makes
sense for python - the reason: in python you have an import
mechanism, where in java you just have namespaces.

Therefore you can always avoid namespace clashes at import time.






感谢您在星期天的回复!


这是我为什么更喜欢这种机制的2美分 -


我不想担心导入时的命名空间冲突。

使用顶层在我看来,将你的命名空间与所有名称空间隔离开来的包是个好主意。

这可能是产品名称(如MoinMoin中的MoinMoin),公司名称

(就像谷歌应用引擎中的谷歌 - 这只是一个短的

com.google btw)或你的DNS。

因此我使用了域名很多次。 (我承认我在java中编程很多就习惯了这个习惯。)


虽然在这种情况下它看起来像我只需要使用

项目名称。


谢谢&此致,

Abhishek Mishra


Hi,

Thanks for your reply on a Sunday!

Here''s my 2 cents on why I prefer this mechanism -

I would like not to worry about namespace clashes at import time.
Using a toplevel package which isolates your namespace from all
others, is a good idea in my opinion.
This could be a product name (like MoinMoin in MoinMoin), company name
(like google in google app engine - which is just one short of
com.google btw), or your DNS.
Therefore I use a domain name lots of times. (I admit that I picked up
this habit from programming a lot in java).

Although it looks like in this case I would have to use just the
project name.

Thanks & Regards,
Abhishek Mishra



2008年10月18日星期六23:05:38 -0700,Abhishek Mishra写道:
On Sat, 18 Oct 2008 23:05:38 -0700, Abhishek Mishra wrote:

我习惯在包名中反向使用域名(应用程序或

公司)。


例如com.spam.app1


我最近开始了一个印度域名项目(tld = .in),

导致一个包名喜欢


in.spam.app1


这导致语法错误,如in是一个关键字。我知道这个

是一个不幸的功能,但是之前有人遇到过这个问题,

并且有可能的解决方法。
I have the habit of using domain names (of either the application or
company) in reverse in package names.

for e.g. com.spam.app1

I''ve recently started a project for an indian domain (tld = .in), which
leads to a package name like

in.spam.app1

This causes a syntax error, as "in" is a keyword. I understand that this
is an unfortunate "feature", but has anyone faced this problem before,
and is there a possible workaround.



`com_spam.app1` !?我甚至会推荐使用不与
冲突的域名,因为如果有几个人开始使用这个包

名称约定,你会在包级别获得名称冲突。在那里说

是两个带有`com`TLD的供应商,你如何安装他们的软件包?

进入同一个`com /`子目录?供应商

的`__init __。py`应该位于`com /`目录级别?如果你将它们安装到两个不同的目录中,但是想从两个供应商那里导入模块 - 怎么样?


Ciao,

Marc''BlackJack''Rintsch

`com_spam.app1`!? I would even recommend this with domains that don''t
clash with keywords because if several people start to use this package
name convention you will get name clashes at package level. Say there
are two vendors with a `com` TLD, how do you install their packages?
Into the same `com/` subdirectory? The `__init__.py` of which vendor
should live at the `com/` directory level? If you install them into two
different directories but want to import modules from both vendors -- how?

Ciao,
Marc ''BlackJack'' Rintsch


Abhishek Mishra写道:
Abhishek Mishra wrote:

Hello Everyone,


我习惯在包名中反向使用域名(应用程序或

公司)。


for例如com.spam.app1


我最近开始了一个印度域名项目(tld = .in),

导致一个包名喜欢


in.spam.app1


这导致语法错误,如in是一个关键字。
Hello Everyone,

I have the habit of using domain names (of either the application or
company) in reverse in package names.

for e.g. com.spam.app1

I''ve recently started a project for an indian domain (tld = .in),
which leads to a package name like

in.spam.app1

This causes a syntax error, as "in" is a keyword.



india = __import __(''in'')

将工作

而你必须在Python中使用别名,你可以在磁盘上拥有你想要的东西

india = __import__(''in'')
will work
while you must alias in Python, you can have what you want on disk


这篇关于包名中的关键字。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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