- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在尝试创建一个非常简单的程序时遇到了这个问题。在另一个名为“timelines”的文件(我导入的)中,我有一个名为“TimeUD”的变量。当用户在 checkAction() 中输入“Universal Development”时,应该打印此字符串。但它却给出了以下错误:
Traceback (most recent call last):
File "C:\Users\****\Desktop\Universe-Simulation\simulation.py", line 84, in <module>
turn1( 0.1 )
File "C:\Users\****\Desktop\Universe-Simulation\simulation.py", line 39, in turn1
checkAction()
File "C:\Users\****\Desktop\Universe-Simulation\simulation.py", line 29, in checkAction
print(timelines.TimeUD)
AttributeError: 'str' object has no attribute 'TimeUD'
>>>
我的程序代码是:
import timelines
#x(forward-back) Axies
global x
x = 0
#y(left-right) Axies
global y
y = 0
#z(up) Axies
global z
z = 0
#t(time) Axies
global t
t = 0
#u(universe) Axies
global u
u = 1
#how much time moves by per-turn, string
global time_change
time_change = 'doggos'
#the timeline, nets of exctinction
timelines = 'Universal Development\nSolar Development\nPlanetary Development\nEvolution\nIntelligence\nContinental Drift\nSpeech\nReligion/Beliefs\nAgriculture\nTechnological Innovation\nSocial Politics\nCommunities\nCivilizations\nWar/Conflicts\nEconomy\nLaw\n----------------------------------------------'
global loop
def checkAction():
ca_loop = 1
while( ca_loop == 1 ):
if turn_action == 'timeline':
which_timeline = input("What timeline would you like to view?\n----------------------------------------------\n" + timelines + "\n[Timelines]~| ")
if which_timeline == "Universal Development":
print(timelines.TimeUD)
else:
print("~|Improper Input|~\n")
def turn1( tc ):
t = 0
global turn_action
while ( loop == 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 ):
t = t + tc
print("The current " + time_change + "s is " + str(t))
turn_action = input("~| ")
checkAction()
input("~|Press enter to continue to the next Time-Period|~")
loop_select = 1
while ( loop_select == 1 ):
loop = int(input("~|Choose a time-change per turn|~\n\n~| "))
if loop == 1:
print("The time-change is set to miliseconds.\n\n")
time_change = 'Milisecond'
loop_select = 0
elif loop == 2:
print("The time-change is set to seconds.\n\n")
time_change = 'Second'
loop_select = 0
elif loop == 3:
print("The time-change is set to minutes.\n\n")
time_change = 'Minute'
loop_select = 0
elif loop == 4:
print("The time-change is set to hours.\n\n")
time_change = 'Hour'
loop_select = 0
elif loop == 5:
print("The time-change is set to days.\n\n")
time_change = 'Day'
loop_select = 0
elif loop == 6:
print("The time-change is set to months.\n\n")
time_change = 'Month'
loop_select = 0
elif loop == 7:
print("The time-change is set to years.\n\n")
time_change = 'Year'
loop_select = 0
elif loop == 8:
print("The time-change is set to cosmic seconds.(a really long time)")
time_change = 'Cosmic Second'
loop_select = 0
elif loop == type.str:
print("~|Improper Input|~")
else:
print("Input is currently inapplicable, try again.\n")
if loop == 1:
turn1( 0.1 )
elif loop == 2 or 3 or 4 or 5 or 6 or 7 or 8:
turn1( 1 )
还有:
#globalization
global TimeUD
global UD
global TimeSD
global SD
global TimePD
global PD
global TimeEv
global Ev
#Universal Development
TimeUD = "Universal Development ~ Timeline:\n\n|------------------------------------------------------------------------------|"
UD = "Universal Development -\nThe timeline of the universe's growth since creation. This timeline will include details about the particles created shortly after the Big Bang, and how they change and evolve until they can create matter. Aswell as the rate of expansion and other factors such as the first Singularities imploded."
#Solar Development
TimeSD = "Solar Development ~ Timeline:\n\n|----------------------------------------------------------------------------------------------------------------------|"
SD = "Solar Development -\nMainly the regarding the development of the sun of the Solar System focused upon, aswell the Solar System itself. This will included information about the solar systems size, planets, sun, and habitable planet(s)."
#Planetary Development
TimePD = "Planetary Development ~ Timeline:\n\n|----------------------------------------------------------------------------------------------------------------------|"
PD = "Planetary Development -\nThis timeline will contain information regarding the initial planet's stages of life. You will find information such as Asteroid Collisions, Vegetation Growth, Seismeic Activities -- the creation and destruction of land, volcanoes, Continental Plates and Positionings, large Seismic Events, and anything related to those -- Moons, and Oceans."
#Evolution
TimeEv = "Evolution ~ Timeline:\n\n|----------------------------------------------------------------------------------------------------------------------|"
Ev = "Evolution -\nDirectly regarding the dominating species of the simulation, the Evolution Timeline will contain information regarding all Evolutionary Events of the Species. Large, or moderate. This will also include Evolutionary Events that have happened when the Species was developing in water."
#Intelligence
TimeIn = "Intelligence ~ Timeline:\n\n|----------------------------------------------------------------------------------------------------------------------|"
In = "Intelligence -\nThe dominate species' level and evolution of their intelligence. This will also include information about the Species' big Philosophies in which highly intleligent variants created amongst the species throughout the species."
#Continental Drift
TimeCD = "Continental Drift ~ Timeline:\n\n|----------------------------------------------------------------------------------------------------------------------|"
CD = "Continental Drift -\nA more detailed timeline of the Planet's Continental Plates moving around throughout the ages. This will regard any large Seismic Events, any super-continentals made, and modern mapping of the planet's continents."
#Speech
TimeSp = "Speech ~ Timeline:\n\n|----------------------------------------------------------------------------------------------------------------------|"
Sp = "Speech -\nThe dominate species' linguistic development. This timeline will include any information regarding the species' languages, the evolution of those languages and parties that use those languages."
#Religion/Beliefs
TimeRB = "Religion/Beliefs ~ Timeline:\n\n|----------------------------------------------------------------------------------------------------------------------|"
RB = "Religion/Belief -\nThe particular belief system(s) put in place by the dominate species, will include Religions aswell as cults throughout all ages. This will also include general values of people, regarding how the way many of the species' will act and perform throughout their lifetime."
#Agriculture
TimeAg = "Agriculture ~ Timeline:\n\n|----------------------------------------------------------------------------------------------------------------------|"
Ag = "Agriculture -\nThis timeline will include information regarding the true first forms of Agriculture, tools and methodology througout the ages. Also the kind of vegetation that is planted on a regard basis."
#Technological Innovation
TimeTI = "Technological Innovation ~ Timeline:\n\n|----------------------------------------------------------------------------------------------------------------------|"
TI = "Technological Innovation-\nAll forms of technologies, tools, and methodology for construction or invention will be put here. This will also include the inventors and/or team behind developing all technology. Also inspiration behind the creations and what it's creator(s) intended for it to do or be of use for."
#Social Politics
TimeSP = "Social Politics ~ Timeline:\n\n|----------------------------------------------------------------------------------------------------------------------|"
SP = "Social Politics -\nThe dominate species' social dynamics. This will include the development and creation of morals, general beliefs and how power is easily gained through social means. Also will contain geography in regard for accents, slang, usage of words and any swear word(s) if they reside. This timeline will also include information about sections of society and details regarding them -- via Lower Class, Middle Class, Upper Class."
#Communities
TimeCo = "Communities ~ Timeline:\n\n|----------------------------------------------------------------------------------------------------------------------|"
Co = "Communities -\nInformation regarding small to large parties of the species' that share at least two of the three communal factors, those factors being as listed: a similar geographical location, similar beliefs and values, and that the party does tasks or performs actions together."
#Civilizations
TimeCi = "Civilizations ~ Timeline:\n\n|----------------------------------------------------------------------------------------------------------------------|"
Ci = "Civilizations -\nAny communities that have the eight Pillars of Civilization, consisting as follows: Public Work-force, Organized Government, Social Policy, Geographical Location, Technological Innovation, Complex Religion/Belief System, Social Dynamics, Martial Arts -- Painting, dance, etc -- and usage of Literature -- Recordings, plus semi-advanced communication relative to humanity via Letters. And information regarding those parties."
#War/Conflicts
TimeWC = "War/Conflicts ~ Timeline:\n\n|----------------------------------------------------------------------------------------------------------------------|"
WC = "War/Conflicts -\nConfliction between societie(s), whether it's a Community or a Civilization. Dates and large events in the wars will be included aswell."
#Economy
TimeEc = "Economies ~ Timeline:\n\n|----------------------------------------------------------------------------------------------------------------------|"
Ec = "Economies -\nSocieties -- whether Communities or Civilizations -- and their economic value. This will include economic growth by percentage, economic relationships and net-changes of societies. Aswell as their Currency in store."
#Law
TimeLa = "Law/Justice System(s) ~ Timeline:\n\n|----------------------------------------------------------------------------------------------------------------------|"
La = "Law/Justice System(s) -\nSocieties -- whether Communities or Civilizations -- and their Justice System. This will include development regarding laws, punishments, form of judgment, and evolution of a Society's moral code."
#print(UD + "\n\n" + SD + "\n\n" + PD + "\n\n" + Ev + "\n\n" + In + "\n\n" + CD + "\n\n" + Sp + "\n\n" + RB + "\n\n" + Ag + "\n\n" + TI + "\n\n" + SP + "\n\n" + Co + "\n\n" + Ci + "\n\n" + WC + "\n\n" + Ec + "\n\n" + La)
#input("\n\nPress Enter to Exit ~(0x0)")
最佳答案
您的行:
timelines = 'Universal Development\nSolar Development\nPlanetary Development\nEvolution\nIntelligence\nContinental Drift\nSpeech\nReligion/Beliefs\nAgriculture\nTechnological Innovation\nSocial Politics\nCommunities\nCivilizations\nWar/Conflicts\nEconomy\nLaw\n----------------------------------------------'
在开始时覆盖您的模块导入:
import timelines
所以当你:
print(timelines.TimeUD)
它尝试以字符串而不是模块的形式访问时间线
的TimeUD
属性。
将您的timelines
字符串变量重命名为其他名称以避免冲突。
关于python - 属性错误: 'str' object has no attribute 'TimeUD' | Variable Calling,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51412753/
for /f "tokens=*" %%a in ('find /v ":" "%appdata%\gamelauncher\options.txt" ^| find "menu=a"') do (
我在 Javascript 中有一组全局计数器变量: var counter_0 = 0; var counter_1 = 0; var counter_2 = 0; 等等 然后我有一个 Javasc
好的,我正在阅读一些有关 RedBlackTrees 的代码。我注意到这一行“v1 = v2 = v3 = v4;”我理解类似“v1 += v2”(将 v2 添加到 v1 的当前值)和“v1 = v2
我正在为 C# 中的游戏数据加载制作一个 csv 阅读器,我想做的就是从数组(变量)的值声明一个变量,我们可以在 php 中像 $$foo 那样做。喜欢 void csvReader(string s
假设我有变量 内容为“ 123 ”和变量 b123 里面有一些文字。出于某种原因,我想使用变量 作为第二个 var 名称的一部分。像这样的东西: SET a=123 SET b123=some_tex
我对 javascript 有点陌生,我无法通过谷歌搜索找到任何内容,我正在编写一个程序,并且能够执行我所要求的操作: if (Variable == 1 或 Variable == 2 或 Vari
我发现我自己在做这种类型的 IF 语句分配。例如: if($variable == 1 || $variable == "whatever" || $variable == '492') { ...
我的虚拟 PC 在 MS-DOS 6.22 上运行时出现问题。 我需要使用变量 Date ,但我无法得到它,因为每当我尝试回显变量时,它都会显示 %variable%反而。 我在 Windows 控制
尝试运行此代码时: List list = em.createQuery("select balance b from Users where b.userName = '" + user_name.
我有一些代码,其中变量可以是 undefined、null 或正常值。无论变量是 undefined 还是 null,代码都需要做同样的事情。说有没有危险 for (var cur = this.bu
我正在编写一个批处理命令脚本,其中检查环境变量。我需要通过传递所有必需的变量来编写一个 FOR 循环,然后验证它是否已定义,如果未定义,则提示该键的值并永久设置该变量。 问题是我无法取消引用循环变量并
我知道这些是 Rails 的基础知识,但我仍然不知道 = 符号和 => 之间的全部区别以及 @some_variable 之间的区别、@@some_variable 和 :some_variable
我正在使用以下内容创建一个动态变量(PHP 术语中的“变量变量”): foo: "test1" set to-word (rejoin [foo "_result_data"]) array 5 但是
我一直在啃 PHP 套接字服务器和客户端的基础知识 here . 然后我偶然发现了这些行(摘自上面链接的第一个示例,发生在 while 中): if (false === ($buf = socket
这个问题在这里已经有了答案: What does "|=" mean? (pipe equal operator) (6 个答案) 关闭 9 年前。 我正在寻找一些编码来扩展我在 Java 方面的知
如何在 C++ 中从其他变量的值打印变量我只是 C++ 的新手。 在 php 中,我们可以通过其他变量的值来制作/打印一个变量。像这样。 $example = 'foo'; $foo = 'abc';
作为 Ruby on Rails 新手,我明白“@”和“:”引用有不同的含义。我看到了this post在 SO 中,其中描述了一些差异。 @ 表示实例变量(例如@my_selection) :表示别
编程新手/甚至更新。一个小的 go 程序有问题 - 不会编译带有 undefined variable 错误。代码: package main import ( "fmt" "io" "o
我知道其他一些语言,如PHP,支持“变量变量名”的概念--即,字符串的内容可以用作变量名的一部分。。我听说总的来说这不是一个好主意,但我认为它可以解决我在Python代码中遇到的一些问题。。有没有可能
我有两个版本的代码。 版本 1 Launcher.java class Launcher { public static void main(String[] args) {
我是一名优秀的程序员,十分优秀!