小编Tho*_*eia的帖子

Python中的两个补码二进制?

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)

python binary bit-manipulation

36
推荐指数
5
解决办法
4万
查看次数

如何每小时呼叫功能?另外,我该如何循环呢?

我需要一种简单的方法来每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)

java timer scheduled-tasks

14
推荐指数
1
解决办法
3万
查看次数

如果我有一个单词列表,如何检查字符串是否包含列表中的任何单词,并且有效?

正如标题所说,我有一个单词列表,喜欢stopWords = ["the", "and", "with", etc...]和我接收的文字如"杀死狐狸和狗".我希望输出像"杀死狐狸狗"非常有效和快速.我怎么能这样做(我知道我可以使用for循环迭代,但那不是很有效)

python search loops filter stop-words

6
推荐指数
1
解决办法
5917
查看次数

如何为命令行命令添加别名?(苹果电脑)

我在Mac上,我写了很多python脚本.

每次我需要运行它们时,我必须输入' python script_name.py'.我有办法做到这一点所以我只需要输入' p script_name.py'?这会节省一些时间:D

python command-line alias command

5
推荐指数
2
解决办法
5020
查看次数

TypeError:在执行open()时期望一个字符缓冲区对象

所以我正在学习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)

python compiler-errors

4
推荐指数
2
解决办法
4万
查看次数

如何用2个参数拆分字符串?

如果我有一个字符串'asdf foo\nHi\nBar thing',我希望它分割字符串,所以输出是['asdf', 'foo', 'hi', 'bar', thing'].那基本上是x.split(' ')x.split('\n').我怎样才能有效地做到这一点?我希望它长约一行,而不是让for循环再次拆分......

python string split

3
推荐指数
1
解决办法
2177
查看次数

如何反向循环?

我正在制作一个水模拟程序,我需要它来循环通过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.

python algorithm simulation loops for-loop

2
推荐指数
1
解决办法
6007
查看次数

如何在Python的诅咒中获得更多颜色?

我正在为学校做一个项目,我正在使用诅咒.虽然,我对颜色的限制有点失望.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,因此没有捷径.

python terminal ncurses

2
推荐指数
2
解决办法
3318
查看次数

当"包含"Django URL模式时,'function'对象不可订阅?

我正在制作一个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)

python django typeerror

1
推荐指数
1
解决办法
2975
查看次数

如何制作"功能字典"?

我有很多函数,如果我有一个数组,[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,因此如果有一种方法可以实现,那么它也会很棒!

python syntax programming-languages

1
推荐指数
1
解决办法
67
查看次数