Python中的整数存储在两个补码中,对吗?
虽然:
>>> x = 5
>>> bin(x)
0b101
Run Code Online (Sandbox Code Playgroud)
和:
>>> x = -5
>>> bin(x)
-0b101
Run Code Online (Sandbox Code Playgroud)
那太蹩脚了.我怎么让python给我真正的二进制位数,而没有它的前面的0b?所以:
>>> x = 5
>>> bin(x)
0101
>>> y = -5
>>> bin(y)
1011
Run Code Online (Sandbox Code Playgroud) 我需要一种简单的方法来每60分钟调用一次函数.我怎样才能做到这一点?我正在制作一个MineCraft bukkit插件,这就是我所拥有的:
package com.webs.playsoulcraft.plazmotech.java.MineRegen;
import java.util.logging.Logger;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin{
public final Logger log = Logger.getLogger("Minecraft");
@Override
public void onEnable() {
this.log.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
this.log.info("Plaz's Mine Regen is now enabled!");
this.log.info("Copyright 2012 Plazmotech Co. All rights reserved.");
this.log.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
@Override
public void onDisable() {
this.log.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
this.log.info("Plaz's Mine Regen is now disabled!");
this.log.info("Copyright 2012 Plazmotech Co. All rights reserved.");
this.log.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
public void onPlayerInteract(PlayerInteractEvent event) {
final Action action = event.getAction();
if …Run Code Online (Sandbox Code Playgroud) 正如标题所说,我有一个单词列表,喜欢stopWords = ["the", "and", "with", etc...]和我接收的文字如"杀死狐狸和狗".我希望输出像"杀死狐狸狗"非常有效和快速.我怎么能这样做(我知道我可以使用for循环迭代,但那不是很有效)
我在Mac上,我写了很多python脚本.
每次我需要运行它们时,我必须输入' python script_name.py'.我有办法做到这一点所以我只需要输入' p script_name.py'?这会节省一些时间:D
所以我正在学习Python.我正在使用数组和open()做一个简单的事情,有时候这段代码可以工作,有时却不行!请帮忙!
print('Load? (Y/N)')
load = raw_input()
if load == "y":
fin = open("myArr.bat", "r")
myArr = fin.readline()
if load == "n":
myArr = [0, 0, 0,
0, 0, 0,
0, 0, 0]
if load != "y" and load != "n":
print 'WUT?'
exit()
print (myArr[0]) , '|' , (myArr[1]) , '|' , (myArr [2])
print '----------'
print (myArr[3]) , '|' , (myArr[4]) , '|' , (myArr [5])
print '----------'
print (myArr[6]) , '|' , (myArr[7]) , '|' , (myArr [8]) …Run Code Online (Sandbox Code Playgroud) 如果我有一个字符串'asdf foo\nHi\nBar thing',我希望它分割字符串,所以输出是['asdf', 'foo', 'hi', 'bar', thing'].那基本上是x.split(' ')和x.split('\n').我怎样才能有效地做到这一点?我希望它长约一行,而不是让for循环再次拆分......
我正在制作一个水模拟程序,我需要它来循环通过y,x.但我需要它先检查最底层,然后再检查.这是我的lvl:
lvl = [[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]]
Run Code Online (Sandbox Code Playgroud)
我需要它来检查lvl [4]然后lvl [3],lvl [2]等等.请帮忙!
注意:我正在使用嵌套for循环,所以我可以检查y,x.
我正在为学校做一个项目,我正在使用诅咒.虽然,我对颜色的限制有点失望.colorama模块有很多颜色,它们可以在我的终端上工作,所以我知道我的终端能够有很多颜色.虽然,在Curses中,我们只有
COLOR_BLACK
COLOR_RED
COLOR_GREEN
COLOR_YELLOW
COLOR_BLUE
COLOR_MAGENTA
COLOR_CYAN
COLOR_WHITE
Run Code Online (Sandbox Code Playgroud)
如果有更多的颜色,那将是非常好的.
注意:Colorama提供ANSI转义码,不适用于Curses,因此没有捷径.
我正在制作一个Django网站,关于我在http://youtube.com上观看的教程,我遇到了问题.这是我的urls.py脚本:
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
(r'^', include['FirstBlog.apps.homepage.urls']),
# Examples:
# url(r'^$', 'FirstBlog.views.home', name='home'),
# url(r'^FirstBlog/', include('FirstBlog.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
# url(r'^admin/', include(admin.site.urls)),
)
Run Code Online (Sandbox Code Playgroud)
我的输出:
TypeError at /
'function' object is not subscriptable
Request Method: GET
Request URL: …Run Code Online (Sandbox Code Playgroud) 我有很多函数,如果我有一个数组,[echo, "Bob is Good"]我想用整个数组的参数运行echo函数.因此,它需要arr[0]并使用整个数组的参数运行该函数.现在我只有if语句,例如:
...
elif arr[0] == 'echo':
echo(arr)
elif arr[0] == 'var':
var(arr)
Run Code Online (Sandbox Code Playgroud)
此外,最好,现在我的功能设置为前缀cmd.例如,echo函数将被称为echocmd,因此如果有一种方法可以实现,那么它也会很棒!