标签: line

在python中读取.txt文件

我的 python 代码有问题。我想读取 .txt 文件。我使用代码:

f = open('test.txt', 'r')  # We need to re-open the file
data = f.read()

print(data)
Run Code Online (Sandbox Code Playgroud)

我只想读取此 .txt 文件中的第一行。我用

f = open('test.txt', 'r')  # We need to re-open the file
data = f.readline(1)

print(data)
Run Code Online (Sandbox Code Playgroud)

但我看到屏幕上只显示该行的第一个字母。

你能帮我读出这一行的所有字母吗?(我的意思是读取 .txt 文件的整行)

python command line

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

使用乌龟图形绘制虚线

from turtle import Turtle, Screen
tt_turtle_obj = Turtle()

for _ in range(15):
    tt_turtle_obj.forward(10)
    tt_turtle_obj.color("white")
    tt_turtle_obj.forward(10)
    tt_turtle_obj.color("black")

screen = Screen()
screen.exitonclick()
Run Code Online (Sandbox Code Playgroud)

我用这段代码做了同样的事情。还有其他办法吗?

python line turtle-graphics python-turtle

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

如何在C#中连接三行代码?

我正在使用Visual Studio 2010 C#创建一个应用程序.

我的代码中有一个字符串内嵌,导致代码无法编译.该字符串包含换行符,因此跨越多行,而不是在一行上.

我应该怎么做,以便我可以保持字符串与换行符,但也使我的代码编译?

c# line visual-studio-2010

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

RandomRange TMemo Lines

我会从Memo1中选择一个随机行,然后将其作为链接运行,我尝试了这段代码:

ShellExecute(Handle, 'open', PAnsiChar(RandomRange(Memo1.Lines[1], Memo1.Lines.Count)), nil, nil, SW_SHOWNORMAL) ;
Run Code Online (Sandbox Code Playgroud)

但是出现错误:

Unit1.pas(86): E2010 Incompatible types: 'Integer' and 'string'
Run Code Online (Sandbox Code Playgroud)

所以我的问题是:如何从TMemo中选择随机行?

谢谢.

windows delphi line memo

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

PHP中的新行

我正在制作CSV文件,我需要在每个程序后创建一个新行.标准\n\r \n不起作用.

代码如下:

while ($resultD=mysql_fetch_assoc($queryDown)) 
        {
            $csv.= $resultD["first_name"].' , '.$resultD["last_name"].' , '.$resultD["login"].' , '.$resultD["password"].'\n\r';
        }
        $filename= "export.csv";
        $theFile=fopen($filename,"w");
        fwrite($theFile, $csv);
Run Code Online (Sandbox Code Playgroud)

php csv line

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

发送文本后清除cmd

我找到了这个小脚本.我的问题是,如何在每一行之后清除cmd(cls)?

因此,当第一行完成时,它会清除cmd并显示下一行.

有人可以帮忙吗?:)

@echo off
:: Ghost typer
setlocal enableextensions enabledelayedexpansion

set lines=6


set "line1=Twinkle twinkle little star"
set "line2=How I wonder what you are"
set "line3=Up above the world so high"
set "line4=Like a diamond in the sky"
set "line5=Twinkle twinkle little star"
set "line6=How I wonder what you are"


for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"

for /L %%a in (1,1,%lines%) do set num=0&set "line=!line%%a!"&call :type

pause>nul
goto :EOF

:type
set …
Run Code Online (Sandbox Code Playgroud)

clr text cmd typing line

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

你如何在JavaFX中从一个角落到另一个角落?

我想drawLine(0,0,getWidth(), getHeight())在JavaFX中做.我不只是想把数字放在我的行中.以下是JFrame和JavaFX的代码.

package project;

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class main extends JPanel{
    public static void main(String args[])
    {
        JFrame myWindow = new JFrame("Isometric Grid");
        main myPanel = new main(); //myPanel is just a name

        myWindow.setSize(400,400);
        myWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        myWindow.add(myPanel);
        myWindow.setVisible(true);
    }

    //this method will override main and create a custom graphic
    public void paintComponent(Graphics myPen) //change
    {
        super.paintComponent(myPen);
        this.setBackground(Color.BLACK);  
        myPen.setColor(Color.blue);

        myPen.drawLine(0, 0, getWidth(), getHeight());
    }
}
Run Code Online (Sandbox Code Playgroud)

我不想这样做:

package JavaFXApplication14;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene; …
Run Code Online (Sandbox Code Playgroud)

java javafx line

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

在 TradingView 的 pine 脚本中在该月的第一根柱线处绘制垂直线

我想在一个月(对于每日和每周图表)或一年(对于每月图表)的每个第一个柱上绘制一条垂直虚线。我怎样才能做到这一点?我不知道如何获取这些条形索引。

添加: 我在 这篇文章中读到 ,“line.new”的每个指标最多 54 行的限制。但是,当以直方图样式使用绘图函数时(=仅绘制单个垂直直方图条),我无法绘制虚线...并且我更喜欢带有虚线的解决方案...

plot line draw pine-script

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

我无法在 Pygame 中画线

我制作了一个 Pygame 程序,并尝试画一条线。但每次我运行该程序时,它都会向我显示以下内容:

  File "/Documents/game.py", line 47
    pygame.draw.line(win, (255,255,255), (0,375), (500,375))
    ^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

我的代码:

#!/usr/bin/env python
import pygame
from pygame.locals import *
import sys
import threading
import random
import os
base_path = os.path.dirname(__file__)
bg_path = os.path.join(base_path, "imports/bg.png")
bgimg = pygame.image.load(bg_path)
cannon_path = os.path.join(base_path, "imports/cannon.png")
cannonimg = pygame.image.load(cannon_path)
bullet_path = os.path.join(base_path, "imports/bullet.png")
bulletimg = pygame.image.load(bullet_path)
target_path = os.path.join(base_path, "imports/target.png")
targetimg = pygame.image.load(target_path)
icon_path = os.path.join(base_path, "imports/icon.png")
iconimg = pygame.image.load(icon_path)
pygame.init()
win = pygame.display.set_mode((500,500))
pygame.display.set_caption("ShootIt!")
pygame.display.set_icon(iconimg)
while True:
    pygame.time.delay(25)
    for …
Run Code Online (Sandbox Code Playgroud)

python pygame line draw python-3.x

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

需要来自圆心的线的交点吗?

我有一条起点为P1(x1,y1),终点为P2(x2,y2).这条线来自圆心.圆半径为r.需要一个简单的方程来识别圆线相交点?

geometry point objective-c line intersect

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