python – Get pdf bookmarks

I have to make pdf markers and update their first page with those markers. I saw many previous publications related to this, but none answered my question correctly. I want to know how I can identify pdf sentences that are bold and larger. I can identify that from the docx file but I can not do it by pdf. Can anyone give me an advantage that I can start? Or it is possible to convert pdf to doc. Update that doc file and convert that doc file back to pdf in Python.

python – Get the link of an image with Xpath

I explain what I'm doing and what I want to do, I'm getting the information from a page but it loads the images by javasccript, to get them I post to the server to return the piece of html that contains them. For some reason that escapes my understanding, I can not pick up the link correctly using Xpath, this "html" that the server returns to me:




These are all Xpaths that are used but none with the desired result:

                                print response.xpath ('// a / @ href') #no take the entire link
        print "-------------------------------------------"
        print response.xpath ('// img') #no take the entire link
        print "-------------------------------------------"
        print response.xpath ('// img[@class=vc_gitem-zone-img]') #empty
        print "-------------------------------------------"
        print response.xpath ('// *[@class=vc_gitem-zone-img]') #empty
        print "-------------------------------------------"
        print response.xpath ('// @ href') #no take the entire link
        print "-------------------------------------------"
        print response.xpath ('// @ src') #no take the entire link
        print "-------------------------------------------"
        print response.xpath ('normalize-space (// a / @ href)') # do not take the entire link
        print "-------------------------------------------"
        print response.xpath ('// *[@class=vc_gitem-zone-img]/ @ src ') #vacio

The last one that is used is this:

response.xpath ('// a / @ href')

And in console it returns the link half as the others:

data = u'http: //www.siie.com/wp-content/uploads/2 '>

Thanks for your time.

python – How can I create a function for my code?

-3

I'm completely new to python and I'm learning it. I have written the following code but I could not do any function of it. Can anybody help me please?

import pandas like pd
import numpy as np
f = open (& # 39; 1.csv & # 39 ;, & # 39; r & # 39;)
df = pd.read_csv (f, usecols =[0], sep = " t", index_col = False)
Primary_List = df.values.tolist ()
x = 0
y = len (Primary_list)
for i in the range (x, y):
x = i
MyMatrix = Primary_List[x:x + 10]
print (MyMatrix)

python – Primes and SemiPrimes in binary

I am in the middle of re-learning python. My current effort is an implementation around the prime factorization. I'm trying to reproduce something similar to the table found here (in binary):
https://math.stackexchange.com/questions/586010/relative-size-of-most-factors-of-semiprimes-close

The performance seems to be quite terrible. I have examined the profile of the code in cProfile but I do not see any obvious improvement.

I'm considering:
(a) Install PyPy to see if that improves performance and
(b) Take more advantage of Numpy, although it is precisely a bit vague for me. I am working on the following to see if you can help:
https://www.freecodecamp.org/news/if-you-have-slow-loops-in-python-you-can-fix-it-until-you-cant-3a39e03b6f35/

I've already refurbished to eliminate the need for a semiprime list and that helped a bit, but I'm not sure if there are obvious inefficiencies that I'm not seeing.

miller_rabin.py is not mine. I include it here to complete. My effort focuses on the performance of prime_stats_bin.py. I acknowledge that the primality test will be an important component of the cost, I just do not understand why I can not get to 32 bits in a reasonable time. I am running this on a laptop with Windows 10 for 5 years (Core i5, 2.5GHz, 8GB RAM), under Python 3.7.3 (installed yesterday).

Any comment will be welcome.

As for the purpose of this effort, I would like to know if it is reasonable to expect an output for prime numbers of up to 32 bits from this program in a day.

With 32 bits in the main expansion, the list of prime numbers that I generate is approximately 2xe ^ 8, which, given my installation of 32-bit Python, I'm not sure it's maintained.

prime_stats_bin.py
import mathematics
import randomly
import hashlib
import number
from miller_rabin import *
from time import process_time

time1 = process_time ()

iexp = 2 #init exponent
poe = 2 # pieces of eight
mexp = 8 * poe #max exponent
cexp = 2 # exponent of the current
cousins ​​= [2] # List of prime numbers
account = [] # list of accounts (prime numbers, numbers of semiprimos, numbers of semiprimos nearby)

f = open ("prime_stats_bin.txt", "w", encoding = "utf-8")
f.write ("BinDigits  tPrimes  tSemiprimes  tClose semiPrimes  n")
for x in range (iexp, mexp + 1): #initialize lists for all exponents
accounts[1,1,1]) #since are seen in a loop only in odd cousins, initialize with 1s in all counts
for x in the range (3, pow (2, mexp), 2):
if numpy.log2 (x)> = cexp: #output to file when we pass a power of 2
f.write (str (cexp) + ":  t" + str (account)[cexp-2][0]) + "(" + str (round ((account[cexp-2][0]* numpy.log (pow (2, cexp))) / pow (2, cexp), 4)) + ")  t" +
str (account[cexp-2][1]) + "(" + str (round ((account[cexp-2][1]* numpy.log (pow (2, cexp))) / (pow (2, cexp) * numpy.log (numpy.log (pow (2, cexp)))), 4)) + ")  t" +
str (account[cexp-2][2]) + "(" + str (round ((account[cexp-2][2]* numpy.log (pow (2, cexp))) / pow (2, cexp), 4)) + ";" + str (round ((100 * account)[cexp-2][2]) / account[cexp-2][1], 4)) + ")  n")
if cexp% 8 == 0:
f.write (& # 39; elapsed time:% f seconds & # 39;% (process_time () - time1) + " n")
cexp + = 1
if it is_prime (x):
primes.append (x)
for z in the range (iexp, mexp + 1):
yes x <= pow(2,z):
                counts[z-2][0] += 1 #increment count of primes less than z taken to the power of 2
        for y in primes:
            if y*x > pow (2, mexp): # we should only worry about semiprimos that are lower than our upper limit
break
for w in rank (iexp, mexp + 1):
if y * x <= power (2, w):
account[w-2][1]    + = 1 # count in the semiprem increment less than w taken to the power of 2
if x <= pow (y, 2):
account[w-2][2]    + = 1 # count of closing increments (p * q = N, where p <q and q <= p ^ 2) semiprimes less than w taken to the power of 2
f.write (str (mexp) + ":  t" + str (account)[mexp-2][0]) + "(" + str (round ((account[mexp-2][0]* numpy.log (pow (2, mexp))) / pow (2, mexp), 4)) + ")  t" +
str (account[mexp-2][1]) + "(" + str (round ((account[mexp-2][1]* numpy.log (pow (2, mexp-1))) / (pow (2, mexp) * numpy.log (numpy.log (pow (2, mexp)))), 4)) + ")  t "+
str (account[mexp-2][2]) + "(" + str (round ((account[mexp-2][2]* numpy.log (pow (2, mexp-1))) / pow (2, mexp), 4)) + ";" + str (round ((100 * count)[mexp-2][2]) / account[mexp-2][1], 4)) + ")  n")
f.write (& # 39; elapsed time:% f seconds & # 39;% (process_time () - time1) + " n")
f.clock
miller_rabin.py
def _try_composite (a, d, n, s):
if pow (a, d, n) == 1:
false return
for i in rank (s):
if pow (a, 2 ** i * d, n) == n-1:
false return
return True # n is definitely composed

def is_prime (n, _precision_for_huge_n = 16):
if n in _known_primes:
return true
if any ((n% p) == 0 for p in _known_primes) or n in (0, 1):
false return
d, s = n - 1, 0
while not d% 2:
d, s = d >> 1, s + 1
# Return the exact one according to http://primes.utm.edu/prove/prove2_3.html
if n <1373653:
do not return any (_try_composite (a, d, n, s) for a in (2, 3))
if n <25326001:
do not return any (_try_composite (a, d, n, s) for a in (2, 3, 5))
if n <118670087467:
if n == 3215031751:
false return
do not return any (_try_composite (a, d, n, s) for a in (2, 3, 5, 7))
if n <2152302898747:
do not return any (_try_composite (a, d, n, s) for a in (2, 3, 5, 7, 11))
if n <3474749660383:
do not return any (_try_composite (a, d, n, s) for a in (2, 3, 5, 7, 11, 13))
if n <341550071728321:
do not return any (_try_composite (a, d, n, s) for a in (2, 3, 5, 7, 11, 13, 17))
# on the contrary
does not return any (_try_composite (a, d, n, s)
for one in _known_primes[:_precision_for_huge_n])

_known_primes = [2, 3]
_known_primes + = [x for x in range(5, 1000, 2) if is_prime(x)]
departure and time
BinDigits Primes Semiprimes Close semiPrimes
2: 2 (0.6931) 1 (1.061) 1 (0.3466; 100.0)
3: 4 (1.0397) 2 (0.7101) 2 (0.5199; 100.0)
4: 6 (1.0397) 6 (1.0196) 4 (0.6931; 66.6667)
5: 11 (1.1913) 10 (0.8714) 6 (0.6498; 60.0)
6: 18 (1.1697) 22 (1.0031) 9 (0.5848; 40.9091)
7:31 (1.1751) 42 (1,008) 17 (0.6444; 40.4762)
8:54 (1,167) 82 (1.0369) 28 (0.6065; 34.1463)
Elapsed time: 0.140625 seconds
9: 97 (1.1819) 157 (1.0449) 47 (0.5727; 29.9363)
10: 172 (1.1643) 304 (1.0629) 89 (0.6024; 29.2763)
11: 309 (1.1504) 589 (1.0795) 171 (0.6366; 29.0323)
12: 564 (1.1453) 1124 (1.0775) 311 (0.6315; 27,669)
13: 1028 (1.1308) 2186 (1.0937) 584 (0.6424; 26.7155)
14: 1900 (1.1253) 4192 (1.0926) 1086 (0.6432; 25.9065)
15: 3512 (1.1143) 8110 (1.099) 2093 (0.6641; 25.8076)
16: 6542 (1.1071) 15658 (1.1013) 4023 (0.6808; 25.6929)
Elapsed time: 27.906250 seconds
17: 12251 (1.1014) 30253 (1.1026) 7617 (0.6848; 25.1777)
18: 23000 (1.0947) 58546 (1.1041) 14597 (0.6947; 24.9325)
19: 43390 (1.0899) 113307 (1.1041) 27817 (0.6987; 24.5501)
20: 82025 (1.0844) 219759 (1,105) 53301 (0.7047; 24.2543)
21: 155611 (1.0801) 426180 (1.1046) 101532 (0.7047; 23.8237)
22: 295947 (1,076) 827702 (1.1045) 195376 (0.7103; 23.6046)
24: 1077871 (1.0688) 3129211 (1.1036) 721504 (0.7154; 23.0571)
Elapsed time: 292.140625 seconds

Help for breakout in python USING ONLY stddraw, Ayudaaaa!

Cabros, I need help to schedule the breakout, I have only 3 days

Python to sharepoint without credentials

I'm working on a project that wants me to connect to corporate SharePoint and download files using scripts. But they do not want to put a username and password in the scripts or give credentials. How can I access sharepoint from the company's computer? I guess I can assume that everything is connected, so I do not need to enter passwords.

How do I calculate the average rating of a .txt file in Python?

I'm struggling with a Python mission. From a txt.file file, the average rating of each mentor must be calculated. The data in the txt.file file looks like this:

name middle name ________ 6.7 3.5 7.7

name second name ________ 5.1 2.3 8.4

name middle name ________ 7.0 6.0 9.4

This is the code I made:

import systems

def print_grades (input_grades):
degree = input_grades.split ()

grade 1 = degree[0]
grade2 = degree[1]
grade 3 = degree[2]

average_grade = (grade 1 + grade2 + grade3) / 3

def print_mentor (mentor):
mentor_name = mentor.split ("_")

name = mentor_name[0]
ratings = mentor_name [1]

print_grades (input_grades)

& # 39; & # 39; & # 39; Start Program & # 39; & # 39; & # 39;
mentor_grades = open (& # 39; class_grades.txt & # 39;). readlines ()

for mentor in mentor_grades
print_mentor (mentor)

Obviously, this will not result in an output like:

The middle note of the second name is 5.6
The middle note of the second name is 6.3

Can someone help me with the coding to get the output in the previous format?

Question 58114 refers to python module base58

When I tried, the base58 code was not imported and does not appear to be listed in the Python reference documents.

Handling dates and comparisons Python, Pandas and Excel

I have a date and time column[TRANSFER_DATE] in an excel sheet shows the dates formed as
1/4/2019 0:45 when this date is selected, it appears as
04/01/2019 00:45:08 am using a Python script to read this column[TRANSFER_DATE] which shows the date and time as 01/04/2019 00:45:08

However when I try to compare the column[TRANSFER_DATE] with another date I get this error
Only .dt accessor with datetimelike can be used "
ValueError :: "Only the .dt accessor can be used with values ​​similar to those of the data" when evaluating

which implies that those values ​​are not really recognized as date and time values

mask_part_date = data.loc[data[‘TRANSFER_DATE’].dt.date.astype (str) == & # 39; 2019-04-12 & # 39;]

python 3.x – Python3 OOP Tic-Tac-Toe

I'm studying object-oriented programming and decided to apply some things by doing an object-oriented Tic-Tac-Toe.
I wanted to know if you have some clues about what to improve and why!

Class meeting:
"" "Represents a table in a Tic-Tac-Toe game." ""

def __init __ (self):
"" "Initialize a new table.
A board is a dictionary whose key is the position on the board.
and the value can be & # 39; X & # 39 ;, & # 39; O & # 39; or & # 39; & # 39; (which represents an empty position
on the board.) "" "
self.board = {
"TL": "", "TM": "", "TR": "",
"ML": "", "MM": "", "MR": "",
"BL": "", "BM": "", "BR": ""}

def print_board (self):
"" "Print the board." ""
print (self.board["TL"] + "|" + self.board["TM"] 
+ "|" + self.board["TR"] + "|")
print ("- +" * 3)
print (self.board["ML"] + "|" + self.board["MM"] 
+ "|" + self.board["MR"] + "|")
print ("- +" * 3)
print (self.board["BL"] + "|" + self.board["BM"] 
+ "|" + self.board["BR"] + "|")

def _is_valid_move (self, position):
yes it is self.board[position] is " ":
return true
false return

def change_board (auto, position, type):
"" "Receive a position and if the player is & # 39; X & # 39; u & # 39; O & # 39 ;.
Check if the position is valid, modify the board and return the modified board.
Returns None if the movement is not valid. "" "
If it is self._is_valid_move (position):
auto table[position] = type
back self.board
return none

def is_winner (me, player):
"" "Returns True if the player won and False otherwise." ""
yes it is self.board["TL"] == player.type and self.board["TM"] == player.type and self.board["TR"] == player.type or 
auto table["ML"] == player.type and self.board["MM"] == player.type and self.board["MR"] == player.type or 
auto table["BL"] == player.type and self.board["BM"] == player.type and self.board["BR"] == player.type or 
auto table["TL"] == player.type and self.board["ML"] == player.type and self.board["BL"] == player.type or 
auto table["TM"] == player.type and self.board["MM"] == player.type and self.board["BM"] == player.type or 
auto table["TR"] == player.type and self.board["MR"] == player.type and self.board["BR"] == player.type or 
auto table["TL"] == player.type and self.board["MM"] == player.type and self.board["BR"] == player.type or 
auto table["BL"] == player.type and self.board["MM"] == player.type and self.board["TR"] == player.type:
return true
false return


Class player:
"" "Represents a player." ""
def __init __ (self, type):
"" "Initialize a player with the type & # 39; X & # 39; or & # 39; O & # 39 ;." ""
self.type = type

def __str __ (self):
returns the format "Player {}". (self.type)


Class game:
"" "Represents a game of Tic-Tac-Toe.
The game defines player 1 always playing with & # 39; X & # 39 ;. "" "
def __init __ (self):
"" "Initialize 2 players and a board." ""
self.player1 = Player ("X")
self.player2 = Player ("O")
self.board = Board ()

def print_valid_entries (self):
"" "Print the valid entries to play the game." ""
Print("""
TL - top left | TM - upper medium | TR - top right
ML - middle left | MM - center | MR - right middle
BL - bottom left | BM - lower medium | BR - bottom right "" ")

def printing_board (self):
"" "Print the board." ""
self.board.print_board ()

def change_turn (auto, player):
"" "Change the player's turn.
Receive one player and return the other. "" "
if the player is self.player1:
return self.player2
plus:
back self.player1

def won_game (me, player):
"" "Returns True if the player won the game, False otherwise." ""
return self.board.is_winner (player)

def modify_board (auto, position, type):
"" "Receive the position and type of player (& # 39; X & # 39; or & # 39; O & # 39;).
Returns the modified board if the position was valid.
Ask the player to try a different position otherwise. "" "
If self.board.change_board (position, type) is not None:
return self.board.change_board (position, type)
plus:
position = input ("Position not available, please try again:")
return self.board.change_board (position, type)


def play ():
game = Game ()
game.print_valid_entries ()
player = game.player1
num = 9
while num> 0:
num - = 1
game.printing_board ()
position = input ("{} turn, what is your movement?" .format (player))
game.modify_board (position, player.type)
yes game.won_game (player):
Print ("{} is the winner!". Format (player))
break
plus:
player = game.change_turn (player)
if num == 0:
print ("Game over! It's a tie!")


yes __name__ == "__main__":
to play()