小编Hic*_*ick的帖子

在python中将数据写入文件时出错

 a='aa'
>>> f=open("key.txt","w")


>>> s=str(a)
>>> f.write(s)
Run Code Online (Sandbox Code Playgroud)

仍然是key.txt文件仍然是空白..为什么?

python file-io

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

一个python代码,用于将数字从任何基数转换为10的基数,从而产生错误.这段代码有什么问题?

import math 




def baseencode(number, base):
    ##Converting a number of any base to base10

    if number == 0:
        return '0'

    for i in range(0,len(number)):
        if number[i]!= [A-Z]:
            num = num + number[i]*pow(i,base)
        else :
            num = num + (9 + ord(number[i])) *pow(i,base)
    return num

a = baseencode('20',5)
print a 
Run Code Online (Sandbox Code Playgroud)

我得到的错误是

Traceback (most recent call last):
  File "doubtrob.py", line 19, in <module>
    a = baseencode('20',5)
  File "doubtrob.py", line 13, in baseencode
    if number[i]!= [A-Z]:
NameError: global name 'A' is not defined
Run Code Online (Sandbox Code Playgroud)

python

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

如何在C语言中将字符串转换为整数并将其存储在整数数组中?

我想知道如何将字符串转换为integer,而不在C中使用sprintf()

c

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

在C++中插入结构内的向量时出错

如何插入结构内分配的向量?代码是我写的

struct state{
  int time_taken;
  vector<int>time_live(1);
  string loc_name;
  vector<string>loc(1);
};
state A[100];

A[flag1]->loc.insert(flag2);
A[flag1]->time_live.insert(time);

A[flag2]->loc.insert(flag1);
A[flag2]->loc.insert(time);
Run Code Online (Sandbox Code Playgroud)

我得到的错误就是这个

kris_UCS.cpp:11: error: expected identifier before numeric constant
kris_UCS.cpp:11: error: expected ‘,’ or ‘...’ before numeric constant
kris_UCS.cpp:13: error: expected identifier before numeric constant
kris_UCS.cpp:13: error: expected ‘,’ or ‘...’ before numeric constant
kris_UCS.cpp: In function ‘int main()’:
kris_UCS.cpp:60: error: base operand of ‘->’ has non-pointer type ‘state’
kris_UCS.cpp:61: error: base operand of ‘->’ has non-pointer type ‘state’
kris_UCS.cpp:63: error: base operand of ‘->’ …
Run Code Online (Sandbox Code Playgroud)

c++

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

如何在Perl中获取具有多行的对象的输出?

@ver = $session->cmd("sh conf");
Run Code Online (Sandbox Code Playgroud)

这里的变量是ver,它有配置文件,也就是说,它有多行.那么如何在ver不将变量放入循环的情况下获取变量的每一行的输出?

arrays perl grep join map

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

如何在django中查看已注册某个网站的所有用户?

我正在使用django-auth,因此所有用户名都存储在那里.如何在其他应用程序中检索所有这些用户,以对其应用某些权限?像databrowse admin一样,有没有办法浏览用户(用户名)?

django

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

从库中加载图像时出现空指针异常.

这是我从Gallery获取图像的代码.它给出了一个空指针异常并崩溃.我正在测试设备本身的代码,一旦我在库中选择了图像,它就会崩溃.我出错的任何想法?

                     AlertDialog.Builder builder = new AlertDialog.Builder(CreatePod.this);
                        builder.setMessage("Select") .setCancelable(false).setPositiveButton("Gallery", new DialogInterface.OnClickListener() {
                               public void onClick(DialogInterface dialog, int id) {
                                   Intent gallIntent=new Intent(Intent.ACTION_GET_CONTENT);
                                    gallIntent.setType("image/*"); 
                                    startActivityForResult(gallIntent, 10);
                               }
                        })




protected  void onActivityResult(int requestCode, int resultCode, Intent data){


     super.onActivityResult(requestCode, resultCode, data);






        switch (requestCode) {
        case 10:
            if (resultCode == Activity.RESULT_OK) {
                 Bundle extras = data.getExtras();
                   Bitmap b = (Bitmap) extras.get("data");
                   imgView.setImageBitmap(b);

                String timestamp = Long.toString(System.currentTimeMillis());
                   MediaStore.Images.Media.insertImage(getContentResolver(), b, timestamp, timestamp);
                HttpResponse httpResponse;
                ByteArrayOutputStream bao = new ByteArrayOutputStream();

            b.compress(Bitmap.CompressFormat.JPEG, 100, bao);

            byte [] ba = bao.toByteArray(); …
Run Code Online (Sandbox Code Playgroud)

android

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

Haskell代码中没有(Integral [t0])错误的实例

我收到一个错误:

No instance for (Integral [t0]) 当我运行这个haskell代码.

boomBangs xs = [(a,b,c) |a<-[1..xs],b<-[1..xs],c<-[1..xs], xs <- xs `div` 2]
Run Code Online (Sandbox Code Playgroud)

我哪里错了?

haskell

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

Go 服务器未正确响应。

我按照 Go 文档上的示例并为 Go 服务器编译了以下代码:

package main

import (
    "fmt"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}

func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
}
Run Code Online (Sandbox Code Playgroud)

但是当我访问 localhost:8080 时,它没有显示任何内容。

go

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

无法在Haskell中获取列表的总和

fibs = 0 : 1 : zipWith (+) fibs (tail fibs)

sum' :: (Integral a) => [a] -> a
sum' [] = 0
sum' [a] = foldr (+) 0 ([a])

main = do putStrLn "Enter a number:"
          num <- readLn
          sum' (take num fibs)
Run Code Online (Sandbox Code Playgroud)

这是我的代码,以获取递归生成列表的总和.

我本可以完成foldr操作take num fibs,但是我希望能够更好地控制列表,并想要一种方法,我可以将列表中特定元素的总和而不是整个列表.

我哪里错了?

haskell

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

标签 统计

haskell ×2

python ×2

android ×1

arrays ×1

c ×1

c++ ×1

django ×1

file-io ×1

go ×1

grep ×1

join ×1

map ×1

perl ×1