我正在尝试使用动态 URL 将用户带到带有 AngularJS 的外部网站。但是,当点击该链接时,该链接会将用户带到我页面上的路线。
例如,如果我的网址是“mysite.com”,而我的链接是“google.com”。如果我单击此链接,使用href
或ng-href
,它会将我带到我网站上不存在的路线:“mysite.com/google.com”
如何导航到外部 URL?
我的代码示例:
<a href="{{ linkItem.link }}" target="_blank">View file</a>
Run Code Online (Sandbox Code Playgroud)
而linkItem.link
“google.com”。这对于任何网页都无法正常工作,即使对于具有硬编码 href 属性的网页也是如此。
如果有人写“?name (arg)”,我希望我的机器人说出消息的作者 + “,你的名字是” + arg。但是我找不到该消息的作者。
@client.command()
async def name(their_name):
await client.say("{0}, your name is {1}.".format("""author of the message goes here""", their_name))
Run Code Online (Sandbox Code Playgroud) 我不太明白如何datetime.timedelta
解释否定论点。
正值:
>>> from datetime import timedelta
>>> d = timedelta(days=1,seconds=1,microseconds=1,milliseconds=1,minutes=1,hours=1,weeks=1)
>>> (d.days, d.seconds, d.microseconds)
>>> (8, 3661, 1001)
Run Code Online (Sandbox Code Playgroud)
这很简单。带有负值的类似示例如下所示:
>>> from datetime import timedelta
>>> d = timedelta(days=-1,seconds=-1,microseconds=-1,milliseconds=-1,minutes=-1,hours=-1,weeks=-1)
>>> (d.days, d.seconds, d.microseconds)
>>> (-9, 82738, 998999)
Run Code Online (Sandbox Code Playgroud)
根据我的理解,秒和微秒的推导如下:
86399 - (-60-3600-1)
999999 - (-1-1000)
这样对吗?为什么天数等于 -9?
我正在阅读文档的这一部分。但仍然不太了解负值的工作。请分享解释或相关文档链接。谢谢 :)
自从我更新到TensorFlow v1.4后,我无法运行TensorBoard.最初我遇到了一个与之相关的问题flags
(就像我在这里发布的那样).事实上,我重新安装了TensorFlow,并了解到修复程序已经存在,但现在我收到此错误:
Traceback (most recent call last):
File "/opt/python/3.6.3/bin/tensorboard", line 7, in <module>
from tensorboard.main import run_main
ImportError: cannot import name 'run_main'
Run Code Online (Sandbox Code Playgroud)
无论是否提供日志目录,我都会收到此错误.什么是修复,我可以做些什么来调查?
我是Tensorflow ecoysystem的新手.我试图做的是打开上面引用的文件/opt/python/3.6.3/bin/tensorboard
.我看到以下内容:
#!/opt/python/3.6.3/bin/python3.6
# -*- coding: utf-8 -*-
import re
import sys
from tensorboard.main import run_main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(run_main())
Run Code Online (Sandbox Code Playgroud)
我看了看tensorboard.main
,我什么也没看见命名run_main
,但我确实看到了def main
,所以我试图改变import run_main
,并run_main()
以main
但使我回flags
错误.我究竟做错了什么?
我一直在研究一些有关如何制作Discord Python Bot的示例,并且已经看到client
并且bot
几乎可以互换使用,而我找不到要在何时使用哪个。
例如:
client = discord.Client()
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
if message.content.startswith('$guess'):
await client.send_message(message.channel, 'Guess a number between 1 to 10')
def guess_check(m):
return m.content.isdigit()
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
client.run('token')
Run Code Online (Sandbox Code Playgroud)
与
bot = commands.Bot(command_prefix='?', description=description)
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
@bot.command()
async def add(left : int, right : …
Run Code Online (Sandbox Code Playgroud) 情况:
我正在尝试使用 pycord 制作一个简单的不和谐机器人,但每次运行代码时都会出现以下错误:
Traceback (most recent call last):
File "main.py", line 3, in <module>
bot = discord.Bot()
AttributeError: module 'discord' has no attribute 'Bot'
Run Code Online (Sandbox Code Playgroud)
代码:
Traceback (most recent call last):
File "main.py", line 3, in <module>
bot = discord.Bot()
AttributeError: module 'discord' has no attribute 'Bot'
Run Code Online (Sandbox Code Playgroud)
我做了什么:
我已经检查过我是否安装了 pycord 以及我的令牌是否正确。
我正在尝试使用pip install -r requirements.txt
.来维护依赖项.但是,某些必需的包不直接支持Python 3,但可以使用手动转换2to3
.
在做什么时有办法强制自动pip
运行2to3
这些包pip install -r requirements.txt
吗?
我正在学习 Python 并阅读了有关此错误的博客,但我仍然无法清楚地理解这一点。这是我正在编写的代码片段:
for i in included:
global signs,accounts, regions
global sign_name, acc_name, rg_name
if type == "regions":
regions = i
rg_name = regions['data']['region']
if type == "accounts":
accounts = i
acc_name = accounts['data']['account']
print("Stopping account " + acc_name + " in region " + rg_name)
Run Code Online (Sandbox Code Playgroud)
NameError: 全局名称 'acc_name' 未定义。
我正在使用 Python 2.7 如果有人能帮助我理解 Python 中全局名称和起始的概念,那就太好了。提前致谢。
我最近刚刚发现有一种叫做函数注释的东西,但我不太确定如何使用它。这是我到目前为止:
def check_type(f):
def decorated(*args, **kwargs):
counter=0
for arg, type in zip(args, f.__annotations__.items()):
if not isinstance(arg, type[1]):
msg = 'Not the valid type'
raise ValueError(msg)
counter+=1
return f(*args, **kwargs)
return decorated
@check_type
def foo(a: int, b: list, c: str): #a must be int, b must be list, c must be str
print(a,b,c)
foo(12, [1,2], '12') #This works
foo(12, 12, 12) #This raises a value error just as I wanted to
foo(a=12, b=12, c=12) #But this works too:(
Run Code Online (Sandbox Code Playgroud)
如您所见,我正在尝试检查 的类型a …
我有几个函数(a
,b
和c
),我希望它们使用相同的文档字符串。所以我的计划是通过只写一次文档字符串并将其保存到变量来保存行DOCSTRING
。然后我把它放在函数声明下。我在PEP 257中没有找到任何可以解决我的问题的内容......
DOCSTRING = '''
This is a docstring
for functions:
a,
b,
c'''
def a(x, y):
DOCSTRING
# do stuff with x and y
def b(x, y):
DOCSTRING
# do other stuffs with x and y
def c(x, y):
DOCSTRING
# do some more stuffs with x and y
help(a), help(b), help(c)
Run Code Online (Sandbox Code Playgroud)
我实际上认为它可能有效......但我错了,我得到了这个:
Help on function a in module __main__:
a(x, y)
Help on function b in module __main__: …
Run Code Online (Sandbox Code Playgroud) python ×9
discord ×3
discord.py ×2
docstring ×1
href ×1
html ×1
pip ×1
pycord ×1
python-2to3 ×1
python-3.x ×1
redirect ×1
tensorboard ×1
tensorflow ×1
type-hinting ×1