小编Oys*_*ker的帖子

无效的文件错误Python?

我正在尝试编写一个脚本,允许用户创建一个他们想要的任何名称的文件夹,然后创建一个他们想要的任何名称的文件.一旦他们这样做,程序会询问他们3个名字并将它们写入文件.然后我想让用户输入1到3之间的数字并显示他们想要的行数.我现在正在尝试阅读文件时说出了一些错误

TypeError: invalid file: <_io.TextIOWrapper name='C:blah blah ' mode='a' encoding='cp1252'>
Run Code Online (Sandbox Code Playgroud)

代码如下:

import os, sys
folder = input("What would you like your folder name to be?")
path = r'C:\Users\Administrator\Desktop\%s' %(folder)
if not os.path.exists(path): os.makedirs(path)
file = input("What name would you like for the file in this folder?")
file = file + ".txt"
completePath = os.path.join(path, file)
newFile = open(completePath, 'w')
newFile.close()
count = 0
while count < 3:
    newFile = open(completePath, 'a')
    write = input("Input the first and last name of …
Run Code Online (Sandbox Code Playgroud)

python

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

Powershell没有正确阅读负数

我有一个程序,我只是想检查一个负数,但它不喜欢它.有什么提示吗?

$numbers = @(0,1,2,3,4,5,6,7,8,9,-1,-2,-3,-4,-5,-6,-7,-8,-9)
$number = Read-Host "Please input a number: " 
if ($number -le 0)
    {
        Write-Output "Thanks for using the program! Exitting now..."
        $finished = 1
    }
    elseif ($number -notin $numbers)
    {
        Write-Error "Input must be numeric"
        continue
    }
    else
    {
        Write-Host "Good number!"
    }
Run Code Online (Sandbox Code Playgroud)

powershell

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

搜索哈希表中的键和平均关联值Powershell

所以我有一个脚本,我试图获取测试名称并将其存储在哈希表中作为键,然后获得高测试分数和低测试分数并将这2作为值存储.然后,我想采取并允许用户搜索测试名称并查看高分和低分.我目前的情况是:

$testInfo = @{}
$testName = read-host "Please enter the name of the test"
$testHigh = read-host "Please enter the high score of the test"
$testLow = read-host "Please enter the low score of the test"
$testInfo.Add($testName, $testHigh + " " + $testLow
$search = read-host "Please enter the name of the test you'd like to view the average score of"
Run Code Online (Sandbox Code Playgroud)

此代码成功地将高分和低分存储到该测试名称,但我需要一种方法来使用$ search值查找测试的名称.然后平均值部分中存储的两个测试分数.

powershell

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

标签 统计

powershell ×2

python ×1