小编Ben*_*eno的帖子

PermissionError:python中的[Errno 13]

刚刚开始学习一些python,我遇到了如下所述的问题:

a_file = open('E:\Python Win7-64-AMD 3.3\Test', encoding='utf-8')

Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    a_file = open('E:\Python Win7-64-AMD 3.3\Test', encoding='utf-8')
PermissionError: [Errno 13] Permission denied: 'E:\\Python Win7-64-AMD 3.3\\Test\
Run Code Online (Sandbox Code Playgroud)

似乎是一个文件权限错误,如果任何人可以发光一些,将不胜感激.

注:不知道的Python和Windows文件是如何工作的,但我登录到Windows作为管理员和文件夹具有管理员权限.

我尝试更改.exe属性以管理员身份运行.

python python-3.x

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

这个算子是什么*= -1

我正在进行一些Python活动,并使用此运算符给出了示例代码: y *= -1

我查看了相关的Python文档,但无济于事.

我知道y += 1,例如,它是简称y = y + 1.那么这个y = y * -1y等于y乘以-1可能吗?

在Python文档我能找到最近的事情是这样的:x * y:x和y的产品

是这个吗?

python

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

打印语句对齐和填充

如果标题有点误导,请原谅我,但我对相关的标题名称有点不确定.

我试图围绕一些像文本片段的文本框:

Die1 = random.randint(1,10)
Die2 = random.randint(1,10)
Die3 = random.randint(1,10)

if Die1 > Die2:
    print ("+------------------------------+")
    print ("|  Die 1:  |       |    Die 2  |")
    print ("|    %d     |       |      %d    |" % (Die1,Die2))
    print ("+------------------------------+")


else:
    print ("+------------------------------+")
    print ("|  Die 1:  |       |    Die 2  |")
    print ("|    %d     |       |      %d    |" % (Die1,Die2))
    print ("+------------------------------+")
Run Code Online (Sandbox Code Playgroud)

如果我得到1位数字的结果,这都是花花公子:

+------------------------------+
|  Die 1:  |       |    Die 2  |
|    2     |       |      6    |
+------------------------------+
Run Code Online (Sandbox Code Playgroud)

然而,twp数字将给我这个:,另一个空间将被推出两个十.

+------------------------------+
| …
Run Code Online (Sandbox Code Playgroud)

python python-2.7 python-3.x

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

大写字功能

我正在写一个函数,它应该接受一个字符串输入并返回每个单词的每个首字母作为大写字母的字符串,我已经达到了一定程度.

我的代码:

string = input("Please Enter A string:")

def capitalize_words(string):
    split = string.split()

    letter1 = ''
    letter2 = ''
    letter3 = ''

    str1 = split[0]
    str2 = split[1]
    str3 = split[2]

    for i in str1:
        if i in str1[0]:
            first = i.upper()
        else:
            letter1 = letter1 + i
            string1 = (first+letter1)

    for i in str2:
        if i in str2[0]:
            first = i.upper()
        else:
            letter2 = letter2 + i
            string2 = (first+letter2)

    for i in str3:
        if i in str3[0]:
            first …
Run Code Online (Sandbox Code Playgroud)

python

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

不等于(!=)未按预期运行

首先,你看到这个代码有问题;

 SELECT num,
        surname, 
        firstname,
        ward 
   FROM doctor, ward WHERE num != consultant;

  NUM SURNAME    FIRSTNAME  W
---------- ---------- ---------- -
  203 Black      Peter      A
  574 Bisi       Mavis      B
  461 Boyne      Steve      B
  530 Clark      Nicola     C
  405 Mizzi      Nicola     A
  501 Mount      Mavis      A
  203 Black      Peter      A

  C NAME       CONSULTANT
  - ---------- ----------
  A Surgical          203
  B Paediatric        574
  C Medical           530
Run Code Online (Sandbox Code Playgroud)

我期待输出是这样的;

 461 Boyne      Steve      B
 405 Mizzi      Nicola     A
 501 Mount      Mavis      A
Run Code Online (Sandbox Code Playgroud)

会显示出不相等的结果,但是当我执行命令时,结果是这样的;

       NUM SURNAME …
Run Code Online (Sandbox Code Playgroud)

sql oracle

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

Python if语句

print("this program will calculate the area")

input("[Press any key to start]")

width = int(input("enter width"))
if width < 0:
    print ("please chose a number between 0-1000")
    width = int(input("enter width"))

if width > 1000000:
    print ("please chose a number between 0-1000")
    width = int(input("enter width"))

height = int(input("Enter Height"))

area = width*height

print("The area is:",area)
Run Code Online (Sandbox Code Playgroud)

有没有办法可以压缩下面的代码,例如将它们放在一起,这样我就不必编写相同的代码行,除了那么少,然后更大的语句两次.

width = int(input("enter width"))
if width < 0:
    print ("please chose a number between 0-1000")
    width = int(input("enter width"))

if width > 1000000:
    print …
Run Code Online (Sandbox Code Playgroud)

python

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

解析错误:语法错误,意外'$ query'(T_VARIABLE)

晚上好,

我有这个脚本的问题,我希望你们中的一个优秀的程序员可以告诉我错误的位置.

<?php

mysql_connect("127.0.0.1", "root", "") or die (mysql_error());
echo "Connected to MYSQL ";
mysql_select_db("tutorial") or die (mysql_error());
echo "Connected to Data Base"
$query = "SELECT * FROM forr1";
$result = mysql_query ($query) or die (mysql_error());
while ($row = mysql_fetch_array($result)) {
        echo $row['input1'];


?>
Run Code Online (Sandbox Code Playgroud)

输出

Parse error: syntax error, unexpected '$query' (T_VARIABLE) in C:\Program Files (x86)\EasyPHP-12.1\www\Output.php on line 7
Run Code Online (Sandbox Code Playgroud)

我必须遗漏一些重要的东西,因为无论我如何尝试和返工,我都会得到同样的错误.

谢谢你的时间

php mysql

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

方法返回类型忽略

我试图得到这个方法,我把x*y的值作为long返回.但是,它返回一个int.据我所知,在方法头中指定返回long是需要做什么的?

我无法得到所需的结果,我错过了什么?

public class Returnpower 
{

    public long power(int x,int n) 
    {   
        int total = x * n;
        if(x < 0 && n < 0)
        {
            System.out.println("X and/or N are not positive");
            System.exit(0);
        }
        return (total);

    }

    public static void main(String[] args)
    {
        Returnpower power = new Returnpower();

        System.out.println(power.power(99999999,999999999));
    }
}
Run Code Online (Sandbox Code Playgroud)

产量

469325057
Run Code Online (Sandbox Code Playgroud)

谢谢

java

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

复制构造函数冲突?

我有这个更大代码的片段;

    public PizzaOrder(PizzaOrder PizzaOrderCopy)
    {
        this.pizza1 = PizzaOrderCopy.pizza1;
    }
    /**
     * @param args
     */
    public static void main(String[] args)
    {
        // TODO Auto-generated method stub
        PizzaOrder pizzorder = new PizzaOrder();

        pizzorder.setNumPizza(1);
        pizzorder.setPizza1("small",1,1,1);
        pizzorder.setPizza2("medium",3,6,4);
        pizzorder.setPizza3("large",2,4,4);
        pizzorder.getpizza1info();
        pizzorder.getpizza2info();
        pizzorder.getpizza3info();
        pizzorder.calcTotal();

    }
        // TODO Auto-generated method stub      
}
Run Code Online (Sandbox Code Playgroud)

我正在制作一个复制构造函数PizzaOrderCopy并制作PizzaOrders对象Pizza1 的副本.当我构建我的代码

PizzaOrdre pizzaorder = new PizzaOrder(); 
Run Code Online (Sandbox Code Playgroud)

spa出来了

the constructor PizzaOrder is undefined
Run Code Online (Sandbox Code Playgroud)

因为它现在需要一个参数.

我怎么看(最可能是错的)PizzaOrder Copy是一个副本,Pizzaorder是一个副本.所以我想知道为什么他们互相影响?我能想到的唯一解释是它们以某种方式结合在一起.

java

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

回到一个小广场:s

嘿伙伴堆栈溢出,

我已经写了;

public class testing
{
    public String subString(int start, int end) 
    {   
        char[]content = new char[]{0,1,2,3,4,5,6,7,8,9};
        String output ="";
        for (int i = 0; i < content.length;i++)
        {
            if (content[i] >= start && content[i] < end)
            {
                output = output + content[i];
            }
        }
        return output;
    }
    /**
     * @param args
     */

    public static void main(String[] args)
    {

        testing test1 = new testing();

        System.out.println( test1.subString(1,2));
    }

}
Run Code Online (Sandbox Code Playgroud)

退货:

[] 
Run Code Online (Sandbox Code Playgroud)

它的工作方式无论我如何尝试和拆分它将返回正确数量的小方块.我猜它是因为我试图将一个数组元素放在一个字符串中?

返回也需要字符串.

谁能帮我吗.

PS我知道这有一个功能:)

java arrays

-4
推荐指数
1
解决办法
876
查看次数

标签 统计

python ×5

java ×3

python-3.x ×2

arrays ×1

mysql ×1

oracle ×1

php ×1

python-2.7 ×1

sql ×1